bithavoc / express-winston

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

Expose winston instance? #110

Closed James-Firth closed 8 years ago

James-Firth commented 8 years ago

Preface: This is my first time using winston/express-winston but Google did not seem to help with my issue.

I would like to use winston in my express project for both the HTTP request logging via the express-winston middleware but also use it as a general logger in other modules.

I believe to do that I would need to have the instance of the winston logger exposed via express-winston? Unless I can have multiple instances of winston writing to the same log files and not cause issues.

rosston commented 8 years ago

express-winston actually allows you to provide a winston instance to it, using the winstonInstance property. It's documented in the Readme, but it's easily missed under the wall of options. :)

So here's a quick example (not actually working code):

var winston = require('winston');
var expressWinston = require('express-winston');

var router = require('./my-express-router');

var mainLogger = new winston.Logger({
  transports: [new winston.transports.Console()]
});

app.use(expressWinston.logger({
  winstonInstance: mainLogger,
}));

app.use(router);

app.use(expressWinston.errorLogger({
  winstonInstance: mainLogger,
}));
James-Firth commented 8 years ago

Wow I feel silly now, I somehow missed those docs. As you said, it is quite a wall of options though.

Thanks for the help!