bithavoc / express-winston

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

Rewrite expressWinston#errorLogger and expressWinston#logger to use winston.log #10

Closed adamvr closed 11 years ago

adamvr commented 11 years ago

The idea here is that I wanted to be able to do something like this:

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

winston.add(winston.transports.File, { filename: 'output.txt' });
....
app.use(expressWinston());

...and have expressWinston use winston.log to log to the transports added using winston.add.

There was an additional change associated with this. I replaced the loop which logged to each of the transports with the creation of a winston logger (var logger = new winston.Logger({transports: transports})) and a single call to logger.log. I think this is a little bit tidier.

Thanks for the great module guys!

adamvr commented 11 years ago

Also, there is a strange failure in the test suite that I couldn't figure out. I don't use vows so maybe you guys have a better idea of how to fix it. Thanks!

floatingLomas commented 11 years ago

Sorry for the delay. Even though Travis-CI says your changes are passing, they are not (as evidenced by the build details). I've made some changes in master so that Travis-CI works properly; please incorporate (rebase) these into your fork and resubmit a new (passing) pull request.

Also, please don't remove any test elements - we need those to confirm that changes are backwards-compatible rather only add new ones for new functionality.

PS: If you're just trying to pass Winston's existing transports into express-winston, you can do:

expressWinston.logger({
    transports: winston.transports
})

Thanks!

gdw2 commented 10 years ago

For anyone searching around, I think

expressWinston.logger({
    transports: winston.transports
})

should now be

var _ = require('underscore')
expressWinston.logger({
    transports: _.values(winston.default.transports)
})

winston.transports returns an object of constructors which winston-express doesn't accept. winston.default.transports returns an object (key-value pairing) of the actual transports. We only want to pass the values.

bithavoc commented 10 years ago

@gdw2 Thank you, is this something we'd like to add to our Readme? if so, can you send a Pull Request?

Thank you.

gdw2 commented 10 years ago

https://github.com/heapsource/express-winston/pull/26