bithavoc/express-winston

Add custom fields

Enado95 opened this issue · 3 comments

Is there an option to add customer field?

Like for example I want to add a username field to see made the request to me api.

I already have in the msg like this:

  msg: (req, res) => 'Test' + (res.statusCode == 401 ? ' ' : ` Username: ${req.user.perferred_username}`) 

But its quite challenging to search.

Have you tried the dynamicMeta: function(req, res) { return [Object]; } option?

I am using it to write the unique request Id to the logs:

app.use(expressWinston.logger({
  transports: [
    new winston.transports.File({
     ....
    }),
  ],
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json(),
  ),
  dynamicMeta: function(req, res) {
    return { reqId: req.id };
  }
}));

Thanks I'll check it out

This works. Thanks for the assistance @dezoito