2015-10-17 16 views
-1

我試圖安慰這個登錄使用overiding,但我發現了錯誤。代碼工作正常,當我刪除JSON.stringify(arguments[0]),但我需要它在JSON格式。如何通過重寫來以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(); 

}); 
+0

什麼是'參數[0]'開始與?什麼是'arguments.length'?你遇到了什麼錯誤? –

+0

@Paul我在控制檯中獲得無限'\'。 –

回答

-1

轉換一個通用對象爲true J​​SON:

JSON.parse(JSON.stringify(my_generic_object))