0
我試圖使用winston記錄器,但它似乎有一個奇怪的行爲時使用的文件傳輸。也許這是我錯過的東西,我無法弄清楚。 我創建了一個簡單的例子來說明這個問題。它使用摩卡進行測試。winston文件傳輸問題
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
只是用於測試的測試;-)