簡體   English   中英

為什么Winston沒有記錄HTTP請求

[英]Why winston is not logging http request

我正在嘗試使用Winston庫來記錄請求並將其保存到文件中。

logger.debug(req.body);

它保存[object Object]而不是請求正文。 有人知道我在做什么錯嗎?

嘗試這樣做

logger.debug(req.body.toSource());

toSource()方法表示對象的源代碼。

您可以將morgan與winston結合使用以自動記錄所有請求

var logger = new winston.Logger({
transports: [
    new winston.transports.File({
        level: 'info',
        filename: './logs/all-logs.log',
        handleExceptions: true,
        json: true,
        maxsize: 5242880, //5MB
        maxFiles: 5,
        colorize: false
    })
],
   exitOnError: false
}),

logger.stream = {
    write: function(message, encoding){
        logger.info(message);
    }
};

app.use(require("morgan")("combined", { "stream": logger.stream }));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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