We'd like to use Winston for our logging in Node.js. But, we can't figure out how to have two log files: one for just errors, and one for everything else.
Doing this the naive way doesn't work, however: adding multiple winston.transports.File
transports gives an error.
Others have run into this problem, with vague hints of a solution, but no real answer.
Any ideas?
Unfortunately, the patch that pesho mentioned seems to be still not included in the official version (see stephenbeeson's comment in the pull request #149).
So, I used a workaround instead. As winston compares the name attributes, you can fool it by defining the name yourself:
Maybe not elegant, but at least it works.
I just sent a pull request that allows using multiple File transports in one logger. https://github.com/flatiron/winston/pull/149
It is already merged into flatiron/winston.
You can also use my forked repo: https://github.com/pdobrev/winston
You just need to give the transport a custom
name
property so you don't have a collision:You can read more about multiple transports in the docs: https://github.com/winstonjs/winston#multiple-transports-of-the-same-type
In the meantime, you can implement a rudimentary wrapper using the same interface like so
This will cover the basic winston API. could be extended for metadata and so on...