簡體   English   中英

如何通過覆蓋以 JSON 格式輸出它?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM