简体   繁体   中英

Why winston is not logging http request

I am trying to use winston library to log request and save it into a file.

logger.debug(req.body);

It saves [object Object] not the request body. 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.

You can combine morgan with winston to log all requests automatically

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 }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM