bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
796 stars 187 forks source link

Trying to log req.body and I'm given [Object object] in mongodb, but I'm given the actual results I want when I use wiston.transports.console()? #229

Closed ghost-arbiter closed 4 years ago

ghost-arbiter commented 4 years ago

Here's my current code:

app.use(expressWinston.logger({ transports: [ new winston.transports.Console(), new winston.transports.MongoDB({ level: 'info', db: process.env.MONGODB, options: mongoOptions, collection: 'winstonlogs', name: 'ExpressWinstonLogger' }), ], format: winston.format.json(), // winston.format.simple(), // winston.format.combine( // winston.format.colorize(), // winston.format.json() // ), meta: true, // control whether you want to log the meta data about the request (default to true). // requestField: null, // the property of the metadata to store the request under (default 'req'). Set to null to exclude request from metadata // responseField: null, // the property of the metadata to store the response under (default 'res'). If set to the same as 'requestField', filtered response and request properties will be merged. Set to null to exclude request from metadata
msg: 'HTTP {{req.method}} {{req.url}} {{req.headers}} {{req.body}} {{res.statusCode}} {{res.body}} {{res.responseTime}}ms ', // customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}", "HTTP {{req.method}} {{req.url}}" or function(req, res) { return ${res.statusCode} - ${req.method}. Warning: while supported, returning mustache style interpolation from an options.msg function has performance and memory implications under load. // msg: function(req, res) { return ${res.statusCode} - ${req.method} - ${req.headers} - ${req.body} - ${res.statusCode} - ${res.body} - ${res.responseTime}}, expressFormat: false, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors when colorize set to true colorize: false, responseWhitelist: ['status', 'body'], // Array of response properties to log. Overrides global responseWhitelist for this instance requestWhitelist: ['headers', 'query', 'body'], // Array of request properties to log. Overrides global requestWhitelist for this instance // bodyWhitelist: [String], // Array of body properties to log. Overrides global bodyWhitelist for this instance // bodyBlacklist: [String], // Array of body properties to omit from logs. Overrides global bodyBlacklist for this instance }));