Reputation: 34497
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
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
Reputation: 2866
try to do this
logger.debug(req.body.toSource());
The toSource() method represents the source code of an object.
Upvotes: 0