【发布时间】:2013-05-15 00:39:27
【问题描述】:
我正在尝试使用 winston 记录器,但在与文件传输一起使用时它似乎有一个奇怪的行为。也许这是我想念的东西,我无法弄清楚。 我创建了一个简单的例子来说明这个问题。它使用 mocha 进行测试。
var log = require('winston')
log.add(log.transports.File, { filename: 'output.log' });
describe('Logger', function() {
it('should save the 1st message', function(done) {
log.info('1: this is the 1st message', function() {
console.log('done 1')
done()
})
})
it('should save the 2nd message', function(done) {
console.log('before test 2')
log.info('2: this is the 2nd message', function() {
console.log('done 2')
done()
})
})
it('should save the 3rd message', function(done) {
log.info('3: this is the 3rd message', function() {
console.log('done 3')
done()
})
})
}
)
第一条消息保存在 output.log 文件中,但不保存其他消息。实际上,只调用了第一个测试的回调。 'before test 2' 已打印,但 'done 2' 未打印...并且第二条消息也未保存。
但是,当我评论第二行 (log.add(log.transports.File,...) 时,它表现正常,在控制台中显示所有消息。是我遗漏了什么还是一个错误?
我使用的 winston 版本是 0.7.1。
提前致谢。
ps:console.log 仅用于测试测试;-)
【问题讨论】:
标签: javascript logging winston