4

I am creating a object of logMessage.

logMessage = function (msg, severity, vendorId, userName, actionPerformed, priority, traceId, dataSent) {
    this.message = msg;
    this.severity = severity;
    this.vendorId = vendorId;
    this.userName = userName;
    this.actionPerformed = actionPerformed;
    this.priority = priority;
    this.traceId = traceId;
    this.dataSent = dataSent;
};

var msg = new logMessage(err, "High", "none", qry.username, "Error on login call: /req/login", "high", "", qry);
Utility.writeToLoggly(msg);

err ,qry are json objects; How do I convert the the msg object to json object ? I am sending the msg object to loggly for the log management. It would be great if I could send the correctly formated json object to loggly .

k-nut
  • 3,447
  • 2
  • 18
  • 28
Jackal
  • 2,591
  • 3
  • 25
  • 29

2 Answers2

3
logMessage = function (msg, severity, vendorId, userName, actionPerformed, priority, traceId, dataSent) {
    this.message = msg;
    this.severity = severity;
    this.vendorId = vendorId;
    this.userName = userName;
    this.actionPerformed = actionPerformed;
    this.priority = priority;
    this.traceId = traceId;
    this.dataSent = dataSent;
};

var msg = new logMessage(err, "High", "none", qry.username, "Error on login call: /req/login", "high", "", qry);
Utility.writeToLoggly(JSON.stringify(msg));
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
1

you can use the JSON.stringify() function, so just add to your code:

Utility.writeToLoggly(JSON.stringify(msg));
joseluiscc
  • 234
  • 2
  • 5