winston: transports.File stops logger without any error message
I’m trying to use transports.File to save log file in loop with logger. After several logs print out it stops to write log to file and print nothing in console without any error message.
Here is my test code:
import winston from 'winston'
const winstonConfig = {
level: 'debug',
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: 'file/path/to/combined.log',
maxsize: 10 * 1024 * 1024,
maxFiles: 10
})
]
}
let logger = winston.createLogger(winstonConfig)
for(let i=0; i<10000; i++){
logger.debug(i)
}
Is it stdout buffer issue?
I’m using version 3.0.0-rc1 with node:8-alpine image in docker container
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 31 (2 by maintainers)
Commits related to this issue
- Fixes issue #1194 — committed to rcoedo/winston by deleted user 6 years ago
- Fix file transport write behaviour (#1194) — committed to rcoedo/winston by deleted user 6 years ago
- fix issue #1194 - where rotation of files isn't done when tailable is set to true — committed to diag/winston by ledbit 6 years ago
- fix file rolling when tailing is set to true (#1420) * fix issue #1194 - where rotation of files isn't done when tailable is set to true * more fixes to tail rolling + fix & enable unit tests *... — committed to winstonjs/winston by ledbit 6 years ago
- fix file rolling when tailing is set to true (#1420) * fix issue #1194 - where rotation of files isn't done when tailable is set to true * more fixes to tail rolling + fix & enable unit tests *... — committed to Mizumaki/winston by ledbit 6 years ago
@rcoedo commit fixes the issue but there is still an issue with formatting which I think is related to this.
Produces this output to a file:
Output in the console is formatted correctly.
I think this still happens when using the
tailable: true
option.@jansteuer I can reproduce the behavior. When the stream.write tell us to wait for the drain event, the following 15 lines receive a non formatted message for some reason. I tried to find why but I failed.
I believe this is related to how the Logger handles the transports but I’m not sure. Maybe someone with some expertise in winston can guide us to finally fix the file transport 😃
@bouchezb The
winston-daily-rotate-file
issue was identified and has been solved! Give it a shot by installingwinston-daily-rotate-file@next
.While this good news is specifically related to the
winston-daily-rotate-file
Transport and not theFile
Transport, the issue that affectedwinston-daily-rotate-file
couldalso
be affecting theFile
Transport.@billiebbb and @beac0n two questions for you:
I ask the second question because internal stream event bubbling with
winston-daily-rotate-file
is what caused the Transport to close and unpipe itself. This happened during the file rotation process. Some logs might make it into the newly created file before it was closed if they were reported quickly enough. Given the tight loop in @billiebbb’s example code, it might be the case that those logs are buffered and then several files created before theFile
transport has some time to react to its first internal file sending an “I’m done” message (close
orfinish
or something…).