4

我正在创建一个 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是 json 对象;如何将 msg 对象转换为 json 对象?我将msg对象发送到loggly日志管理。如果我可以将格式正确的 json 对象发送到loggly.

4

2 回答 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));
于 2014-11-05T21:59:18.807 回答
1

您可以使用 JSON.stringify() 函数,因此只需添加到您的代码中:

Utility.writeToLoggly(JSON.stringify(msg));
于 2014-11-05T22:10:35.857 回答