bithavoc / express-winston

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

Any way to include optional values in message? #101

Closed ScottChapman closed 8 years ago

ScottChapman commented 8 years ago

I have some req that come in with session information, and would like to be able to display that. But the value doesn't always exist.

Specifically, when my users are logged in there is a session token I want to display: req.user.sessionID

But the value doesn't always exist...

How would I express that in the msg?

rosston commented 8 years ago

You could simply add user to the requestWhitelist. When it doesn't exist, nothing will get logged out on the whitelisted req object.

If you specifically want only the sessionID of user and nothing else, you could additionally provide a requestFilter property to the logger options. The body of your requestFilter function would be something like this:

function(req, propName) {
  if (propName === 'user') {
    return {sessionID: req[propName].sessionID};
  }
}
rosston commented 8 years ago

Closing due to inactivity. I think I've answered the question.