Express-Winston:将快速访问日志写入文件

时间:2017-01-03 18:29:49

标签: javascript node.js express winston

是否可以只将快速写入访问行写入日志文件,并将其他日志保留在控制台中?像这样:

app.use(expressWinston.logger({
    transports: [
        new winston.transports.Console({
            colorize: true
        }),
        new winston.transports.File({
            name: 'access-file',
            filename: 'access-error.log',
            level: 'info' //This setting is what i need to change for access lines only
        })
    ],
    ignoreRoute: function(req) {
        return (req.url === '/healthcheck');
    },
    meta: false, 
    msg: "HTTP {{req.method}} {{req.url}}", 
    colorStatus: true
}));

问题是我不知道如何仅隔离访问日志行。这可能吗?

1 个答案:

答案 0 :(得分:0)

当然,只需配置“访问”的自定义日志记录级别,然后根据需要将其指向文件。

https://github.com/winstonjs/winston#using-custom-logging-levels