Sign In Register

How can we help you today?

Start a new topic

Logging

How can i insert stack trace info to Spark.getLog().error() ?


is not it possible?

Hey Ufuk,


If you want to insert stack trace info into Spark.getLog().error(), you can use a try/catch block and like this:


try

{

   //error code

}

catch(e)   // e is the error caught

{

   Spark.getLog().error(e.stack);

   throw new Error(e);

}


Hope this helps,

- Tony.


Unfortunately my cases don't raise an exception. i already have around 3000 lines of cloud code. i have many common functions. so i need stack trace info for error messages like hacking attempt, null arguments. i need something like this;


function stackTrace() {
    var err = new Error();
    return err.stack;
}
new Error() returns undefined in debugger.

this function returns undefined and it logs undefined;


function stackTrace() {

  try {

    var err = new Error();

    throw err;

  } catch (err) {

      Spark.getLog().error(err.stack);

    return err.stack;

  }

}


{
 "_id": {
  "$oid": "57bd438f9f0f9404a6bc961a"
 },
 "script": "Test",
 "playerId": "578130fd4b5b9d04ab083d5f",
 "log": "undefined",
 "level": "ERROR",
 "ts": {
  "$date": {
   "$numberLong": "1472021391046"
  }
 }
}

this function returns undefined and it logs undefined;


function stackTrace() {

  try {

    var err = new Error();

    throw err;

  } catch (err) {

      Spark.getLog().error(err.stack);

    return err.stack;

  }

}


{
 "_id": {
  "$oid": "57bd438f9f0f9404a6bc961a"
 },
 "script": "Test",
 "playerId": "578130fd4b5b9d04ab083d5f",
 "log": "undefined",
 "level": "ERROR",
 "ts": {
  "$date": {
   "$numberLong": "1472021391046"
  }
 }
}

this function returns undefined and it logs undefined;


function stackTrace() {

  try {

    var err = new Error();

    throw err;

  } catch (err) {

      Spark.getLog().error(err.stack);

    return err.stack;

  }

}


{

 "_id": {

  "$oid": "57bd438f9f0f9404a6bc961a"

 },

 "script": "Test",

 "playerId": "xxx",

 "log": "undefined",

 "level": "ERROR",

 "ts": {

  "$date": {

   "$numberLong": "1472021391046"

  }

 }

}

this function returns undefined and it logs undefined;


function stackTrace() {

  try {

    var err = new Error();

    throw err;

  } catch (err) {

      Spark.getLog().error(err.stack);

    return err.stack;

  }

}


{
 "_id": {
  "$oid": "57bd438f9f0f9404a6bc961a"
 },
 "script": "Test",
 "playerId": "578130fd4b5b9d04ab083d5f",
 "log": "undefined",
 "level": "ERROR",
 "ts": {
  "$date": {
   "$numberLong": "1472021391046"
  }
 }
}

this function returns undefined and it logs undefined;

function stackTrace() {

  try {

    var err = new Error();

    throw err;

  } catch (err) {

      Spark.getLog().error(err.stack);

    return err.stack;

  }

}

{

 "_id": {

  "$oid": "57bd438f9f0f9404a6bc961a"

 },

 "script": "Test",

 "playerId": "xxx",

 "log": "undefined",

 "level": "ERROR",

 "ts": {

  "$date": {

   "$numberLong": "1472021391046"

  }

 }

}

this function returns undefined and it logs undefined;

function stackTrace() {
  try {
  var err = new Error();
  throw err;
  } catch (err) {
  Spark.getLog().error(err.stack);
  return err.stack;
  }
}

{
 "_id": {
  "$oid": "57bd438f9f0f9404a6bc961a"
 },
 "script": "Test",
 "playerId": "xxx",
 "log": "undefined",
 "level": "ERROR",
 "ts": {
  "$date": {
  "$numberLong": "1472021391046"
  }
 }
}


Login to post a comment