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 .

4
  • 2
    JSON.stringify(msg) Commented Nov 5, 2014 at 21:58
  • NB: by convention JS "classes" start with an upper case letter. Commented Nov 5, 2014 at 21:58
  • p.s. Googling for "javascript json output" trivially produces several pages with the correct answer. Commented Nov 5, 2014 at 22:04
  • 1
    BTW: there is no such thing as a JSON object. JSON is a string. Commented Nov 5, 2014 at 22:06

2 Answers 2

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));
Sign up to request clarification or add additional context in comments.

Comments

1

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

Utility.writeToLoggly(JSON.stringify(msg));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.