Can we specify exact which level winston to log?

2019-09-05 17:17发布

问题:

I have a logger of winston below. when I try to debug my app. However when I debug my logs, all my screen gets filled with 'error' level. All my useful logs I have put into 'info'. Is there a way that I can only checking only my 'info' level logs?

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)({
            'timestamp': true,
            level: "info"
        })
    ]
});

回答1:

You can use this handy fork of winston (the downside is that it was forked 3 years ago and doesn't seem to be actively maintained any longer): https://www.npmjs.com/package/winston-levelonly

Alternatively, you can define a custom transport, like shown here: https://github.com/winstonjs/winston/pull/628



标签: winston