transports.File is not flushing on end.
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
node -v
outputs: v10.10.0- Operating System? (Windows, macOS, or Linux)
- Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart)
What is the problem?
File transport is not flushing on exit. Even when flushing per https://github.com/winstonjs/winston#awaiting-logs-to-be-written-in-winston
Steps to reproduce:
'use strict';
let winston = require('winston');
// VERSION: "winston": "^3.1.0",
let file_transport = new winston.transports.File({
filename: `${__dirname}/myfile.log.json`,
});
let logger = winston.createLogger({
transports: [file_transport],
});
async function run() {
for (let i = 0; i < 1000; i++) {
logger.info('message');
}
logger.info('THE LAST MESSAGE');
await new Promise(resolve => {
file_transport.on('finish', resolve);
logger.end();
});
process.exit(1);
}
run();
What do you expect to happen instead?
all messages (including THE LAST MESSAGE) should be written to the file.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:11
Top Results From Across the Web
How to flush winston logs? - node.js - Stack Overflow
There will be nothing that is not flushed. The default winston FileTransport only buffers logs when attempting to open the underlying the file ......
Read more >4.5.4 mysqldump — A Database Backup Program
The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object ......
Read more >EFFECT OF DRIPLINE FLUSHING ON SUBSURFACE DRIP ...
ABSTRACT. The velocity of dripline flushing in subsurface drip irrigation (SDI) systems affects system design, cost, management, performance, and longevity.
Read more >Winston - Best of JS
file ] }); logger.info('Will not be logged in either transport!'); transports.console.level = 'info' ...
Read more >Zlib Flush Modes
In this document, we consider only DEFLATE and not those outer formats. ... moments (e.g. at the end of a record, for transport...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am experiencing the exact same issue, the posted code by @racquetmaster is correct. It makes it almost impossible to use winston with asynchronous processing
I have been following the documentation (below) calling the end() on Logger. I also tried directly on (File) Transport like @racquetmaster without success. IMO this is a very important issue.
This is still a major problem searched on internet. Graceful exit is okay to advise but most cases, developers just call exit(), which does not executes all pending async task. But this “caution” advisory must be shouted loudly in Winston documents. Program must wait to drain everything, do you think it is obvious to guess this, even knowing node is async? Make it easy for developers to create robust and reliable logging. Could there be a sync call that returns when all transports are written and flushed.
Found this, https://www.npmjs.com/package/winston-log-and-exit after wasting 6-7 hours.