bithavoc / express-winston

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

Request: Metadata flag per winston instance? #145

Closed James-Firth closed 7 years ago

James-Firth commented 7 years ago

Please correct me if I'm missing something obvious.

I'd like to enable the meta-data logging on my verbose/error logging but only on the file transport. On the console transport I'd still like a clean metadataless log.

I don't believe this is possible currently is it? If not, I'd like to request this feature!

Thanks!

rosston commented 7 years ago

No, you're not missing anything obvious. It is possible—just not obvious. The trick is to use two request loggers:

app.use(expressWinston.logger({
    transports: [new winston.transports.Console()],
    meta: false
}));

app.use(expressWinston.logger({
    transports: [new winston.transports.File({filename: 'somefile.log'})],
    meta: true
}));

My day job has been running multiple loggers like this for almost 2 years without issue.

James-Firth commented 7 years ago

Ah that makes sense, thanks for the information!

I'll be implementing that for my day job as well on Monday.

Thanks again!