小编use*_*142的帖子

Winston:尝试写没有传输的日志

我正在尝试使用Winston为我的快速服务器设置访问日志和错误日志,但我似乎做错了什么.

这是我对配置文件的尝试:

const winston = require('winston'),
    fs = require('fs');

const tsFormat = () => (new Date()).toLocaleTimeString();
winston.loggers.add('errorLog', {
        file: {
                filename: '<path>/errors.log', //<path> is replaced by the 
                timestamp: tsFormat,           //absolute path of the log
                level: 'info'
        }

});
winston.loggers.add('accessLog', {
        file: {
                filename: '<path>/access.log', //same as before
                timestamp: tsFormat,
                level: 'info'
        }
});
Run Code Online (Sandbox Code Playgroud)

这就是我将其包含在我的其他文件中的方式:

var winston = require('winston'),
    accessLog = winston.loggers.get('accessLog'),
    errorLog = winston.loggers.get('errorLog');
Run Code Online (Sandbox Code Playgroud)

在我看来,它似乎遵循文档(https://github.com/winstonjs/winston/tree/2.4.0#working-with-multiple-loggers-in-winston)但我在尝试时遇到此错误登录到它:

[winston] Attempt to write logs with no transports {"message":"pls","level":"info"}
[winston] Attempt to write …
Run Code Online (Sandbox Code Playgroud)

node.js npm express winston

10
推荐指数
1
解决办法
7208
查看次数

标签 统计

express ×1

node.js ×1

npm ×1

winston ×1