Home > Blockchain >  How to retrieve entire Logger output?
How to retrieve entire Logger output?

Time:01-03

I have large sets of data (mainly arrays and objects with many elements) and I am trying to log out the entire result to check for bugs. However, in some cases it says "Logging output too large. Truncating output." Where can I see the output in its entirety? I am working with Map Objects and trying to debug why my calculations don't match Google's output.

CodePudding user response:

Logger.log is limited to the number of lines that it can contain. However you can make your own logger and save it to a text file.

var Log = null;

function testLogger() {
  try {
    Log = new LogFile("testLogFile");
    test1();
    test2();
    throw "done"
  }
  catch(err) {
    Log.log(err);
    Log.save();
  }
}

function test1() {
  Log.log("in test1");
}

function test2() {
  Log.log("in test2");
}

class LogFile {
  constructor (name) {
    if( name === undefined ) name = "_LogFile"
    this.name = name;
    this.text = [];
  }
  log(text) {
    this.text.push(text);
  }
  save() {
    try {
      let text = "";
      this.text.forEach( line => text = text.concat(line,"\n") );

      let files = DriveApp.getFilesByName(this.name);
      let file = null;
      if( files.hasNext() ) {
        file = files.next();
        file.setContent(text);
      }
      else {
        DriveApp.createFile(this.name,text);
      }
    }
    catch(err) {
      Logger.log(err);
    }
  }
}

The text file is shown below.

enter image description here

  • Related