Last active
July 17, 2017 00:46
-
-
Save ShaneDunn/62e231018f8f8f4592d8eb2868786677 to your computer and use it in GitHub Desktop.
Google Apps Script - Looging functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Logging and configuration functions adapted from the script: | |
| * 'A Google Apps Script for importing CSV data into a Google Spreadsheet' by Ian Lewis. | |
| * https://gist.github.com/IanLewis/8310540 | |
| * @author ianmlewis@gmail.com (Ian Lewis) | |
| * @author dunn.shane@gmail.com (Shane Dunn) | |
| * De Bortoli Wines July 2017 | |
| */ | |
| /* =========== Globals ======================= */ | |
| /** | |
| * The output text that should be displayed in the log. | |
| * @private. | |
| */ | |
| var logArray_; | |
| /* =========== Logging functions ======================= */ | |
| /** | |
| * Clears the in app log. | |
| * @private. | |
| */ | |
| function setupLog_() { | |
| logArray_ = []; | |
| } | |
| /** | |
| * Returns the log as a string. | |
| * @returns {string} The log. | |
| */ | |
| function getLog_() { | |
| return logArray_.join('\n'); | |
| } | |
| /** | |
| * Appends a string as a new line to the log. | |
| * @param {String} value The value to add to the log. | |
| */ | |
| function log_(value) { | |
| logArray_.push(value); | |
| var app = UiApp.getActiveApplication(); | |
| var foo = app.getElementById('log'); | |
| foo.setText(getLog_()); | |
| } | |
| /** | |
| * Displays the log in memory to the user. | |
| */ | |
| function displayLog_() { | |
| var uiLog = UiApp.createApplication().setTitle('Report Status').setWidth(400).setHeight(500); | |
| var panel = uiLog.createVerticalPanel(); | |
| uiLog.add(panel); | |
| var txtOutput = uiLog.createTextArea().setId('log').setWidth('400').setHeight('500').setValue(getLog_()); | |
| panel.add(txtOutput); | |
| SpreadsheetApp.getActiveSpreadsheet().show(uiLog); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment