In Multi user apps script logger I introduced how you could integrate logging from apps script with another technology. In this case a Polymer app. Further down the page, a live demo will have been kicked off as you are reading this..
// the Dogger defaults you like to use are already set up in your library var Dogger = yourDoggerServer.getDogger(false); // we'll use this additional thread for verbose reporting var Verbose = yourDoggerServer.getDogger(false, 'verbose'); function doSomeStuff(e) { // clear the log before starting (there's no thread so it will clear the whole thing Dogger.clear(); // try various logging Dogger.log('Im starting'); for (var i = 0 ; i < 4 ; i++) { Verbose.log(Math.random()); } Dogger.log ('heres an object'); Dogger.log ({str:'im an object', num:20, bool: true}); // what happens if we try to report a library object Dogger.log ('handler object up next'); Dogger.log(Dogger); // an array Verbose.log([1,2,3,4,5]); // simulate some time passing and things happening for (var i = 0 ; i < 10 ; i++) { Verbose.log('Im doing something very busy ' + i); Utilities.sleep (2000); } // im done Dogger.log('Im done'); }
Starting up
// the Dogger defaults you like to use are already set up in your library var Dogger = yourDoggerServer.getDogger(false);
Now everywhere I would use Logger.log() , I can use Dogger.log(). You could even assign this to replace the Logger if you want (Logger = Dogger) and continue using Logger.log().
What does it log
- seq – the row number
- time – the time it was logged at
- fromstart – how many seconds from the first log entry
- fromprevious – how many seconds since the previous log entry
- type – the data type of the message (Dogger.log(message))
- value – the value of the message. If message was an object you’ll get a stringified version
- length – the length of the message if relevant
- caller – the name of the function that called the .log()
- line – the line number where the call happened
- file – the script file name containing the call
- _timeStamp – the time it as logged as a timestamp
- _thread – where given, the logging thread this message belongs to – more about threads shortly
- name – the name of the object type of the message (if identifiable)
- nargs – the number of arguments the constructor of an object like this is built to expect where known
Threads
// we'll use this additional thread for verbose reporting var Verbose = yourDoggerServer.getDogger(false, 'verbose');
From then on I can use Dogger.log(message) to create a message with no thread, and Verbose.log(message) to assign a thread name to the message. You can see in the image below that the messages that have a thread value were written with Verbose.log() in the example given earlier.
A note on performance
Getting started
Try the demo [Deprecated]
- the inspector by default will be in demo mode
- it will clear the log file and kick off the Apps Script example above
- The Apps script example will Log stuff to a database
- The inspector will show the log as entries arrive.
For help and more information join our community, follow the blog or follow me on Twitter . For more on this topic see Multi user apps script logger