我想在winston
应用中使用node
记录器来记录日志错误。但是winston
没有写入文件。
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({ filename: 'somefile.log' })
]
});
logger.error('test');
文件somefile.log
已创建但为空。
答案 0 :(得分:2)
您需要在构造函数中定义一个级别。
var tsFormat = () => (new Date()).toLocaleTimeString();
var log = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
timestamp: tsFormat,
colorize: true,
level: 'info'
}),
new (winston.transports.File)({
filename: 'somefile.log',
level: 'error'
})
]
});
log.error('test'); // writes to log and console out
log.info('testing info'); // writes just in console