N Sharma
N Sharma

Reputation: 34497

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 ?

Upvotes: 1

Views: 3415

Answers (2)

Py4object
Py4object

Reputation: 11

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

Upvotes: 1

Francesco Taioli
Francesco Taioli

Reputation: 2866

try to do this

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

The toSource() method represents the source code of an object.

Upvotes: 0

Related Questions