简体   繁体   English

为什么Winston没有记录HTTP请求

[英]Why winston is not logging http request

I am trying to use winston library to log request and save it into a file. 我正在尝试使用Winston库来记录请求并将其保存到文件中。

logger.debug(req.body);

It saves [object Object] not the request body. 它保存[object Object]而不是请求正文。 Does anyone know what I am doing wrong ? 有人知道我在做什么错吗?

try to do this 尝试这样做

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

The toSource() method represents the source code of an object. toSource()方法表示对象的源代码。

You can combine morgan with winston to log all requests automatically 您可以将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