I have a Node.js program with a long process with some internal logging:
console.log(msg)
When I run on Windows Node.js, the message is not displayed in real time - I get a large number of messages in the same late time.
When I use "console.warn" instead of "console.log", the messages display earlier, but still not in real time.
Is there a way to tell Node.js to automatically flush the console buffer after each log message?
It turns out that console.log
is asynchronous in Windows. In linux/unix it is blocking, so it's not buffering and needing a flush, putting your console.logs
on the event queue.
One alternative may be process.stdout
Edit: ok that's not a solution. Someone else may have a better solution, but you can either use one of the more comprehensive logging libraries or populate your console.log with more info that tells you when and where the log occurred so you can correlate them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.