In Setting up your Apps Script Environment for Dogger, I showed how you could set up a mini environment wrapper so you could always use the same back end environment and serve up logging data to external, non apps script clients.
It is possible to use the cDogger library directly instead, which avoids having to set up your own library, but it also needs a little more set up in your script you want to log from.
The steps are
  • Include the necessary library
  • Get a dbabstraction handler for the type of database you want to use
  • Get a dogger handle
  • Start logging
In these examples I’ll show how to get a sheet handler, a parse.com , and a mongolab handler directly, but you can substitute for any other driver if you prefer.

Libraries

The libraries needed for parse.mongolab and sheet demos are
cDriverParse
      cDbAbstraction
      cDriverSheet
      cDogger
      cDriverMongoLab

you can get info about them below

Get dbAbstraction handlers

For parse.com (see DriverParse for more info)
// note i have my parse credentials already stored here
function getParseHandle () {
  return new cDbAbstraction.DbAbstraction(cDriverParse, {
    driverob:JSON.parse(PropertiesService.getScriptProperties().getProperty('parseKeys')),
    siloid:'doggerlogger',
    dbid:'xliberation'
  });
}

for Sheets (see DriverSheet for more info)

function getSheetHandle() {
  return new cDbAbstraction.DbAbstraction(cDriverSheet, {
    siloid:'doggerlogger',
    dbid:'1yTQFdN_O2nFb9obm7AHCTmPKpf5cwAd78uNQJiCcjPk'
  });
}

For MongoLab (see Driver MongoLab for more info)

function getMongoHandle () {
  return parseHandle = new cDbAbstraction.DbAbstraction(cDriverMongoLab, {
    driverob:JSON.parse(PropertiesService.getScriptProperties().getProperty('mongoLabKeys')),
    siloid:'doggerlogger',
    dbid:'xliberation'
  });
}

Get Dogger handlers

function getDogger (handle, thread) {
  return new cDogger.Dogger(handle, {
    clearfirst:false,
    thread:thread,
    failsilently:false
  });
}

Start Logging

// do some single thread tasks
function simpleParse(){
  var dogger = getDogger(getParseHandle());
  dogger.clear();
  doSomeLogs(dogger);
}
// do some single thread tasks
function simpleSheet() {
  var dogger = getDogger(getSheetHandle());
  dogger.clear();
  doSomeLogs(dogger);
}
// do some single thread tasks
function simpleMongo() {
  var dogger = getDogger(getMongoHandle());
  dogger.clear();
  doSomeLogs(dogger);
}

Here’s the simulated workload that’ll be doing the logging

function doSomeLogs(dogger) {
  
  // try various logging
  dogger.log('Im starting');
  
  for (var i = 0 ; i < 4 ; i++) {
    dogger.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
  dogger.log([1,2,3,4,5]);
  
  // simulate some time passing and things happening
  for (var i = 0 ; i < 10 ; i++) {
    dogger.log('Im doing something very busy ' + i);
    Utilities.sleep (2000);
  }
  
  // im done
  dogger.log('Im done');
  
}

And here’s the output in a sheet

and in the parse.com dashboard

And in the mongolab dashboard

Of course it looks better and more consistent if you use the Multi user apps script logger polymer client, but for that you need to have set up yourDoggerServer as described in Setting up your Apps Script Environment for Dogger

For more on this see Multi user apps script loggerPolymer and Database abstraction with google apps script

For help and more information join our community,  follow the blog or follow me on twitter.