[英]How can I output this in JSON format by overriding?
我正在尝试使用覆盖来控制台记录此日志,但出现错误。 当我删除JSON.stringify(arguments[0])
,代码工作正常,但我需要 JSON 格式。
app.use(function(req, res, next) {
var t_log= console.log;
console.log = function(){
arguments[0] = JSON.stringify(arguments[0])+" sessionID " + req.sessionID + " requestID=" + req.id +" timestamp"+ new Date();
t_log.apply(console, arguments);
}
console.log("call");
next();
});
将通用对象转换为真正的 JSON:
JSON.parse(JSON.stringify(my_generic_object))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.