Open mlandisbqs opened 4 years ago
Thank you for posting your close()
function - it works like a charm for me (also in a wrapper with a console, daily-rotate-file, and custom sentry transport). π
Waiting for a log to close is basic and the lack of these contracts is a weakness that makes the library difficult to deal with, so thanks for posting your workaround.
Please tell us about your environment:
winston
version? ^3.2.1winston@2
winston@3
node -v
outputs: v12.16.2What is the problem?
I have a seeding script that runs locally and in builds. It relies on a winston logger that can be configured with multiple transports, including a remote sink over UDP (papertrail), and a daily rotate file transport. When the main function completes and is done with the logger the last line executes logger.close(). The code hangs waiting for the transports to close.
It's very important for the seeding script to exit cleanly and accurately. The build should fail if there is a seeding error - which is based on the return code.
Also: I could not find any clear documentation on how to shut down your logger (and it's transports). I spent a lot of time today dissecting winston code to figure out what is happening.
Lacking a contract for shutting down, each Transport handles things differently.
My workaround below takes advantage of this, but since it relies on the implementation detail and not a contract, the code could break when we upgrade winston.
What do you expect to happen instead?
Other information
Here is a workaround... the winston logger is wrapped in a nestjs LoggerService
LoggerService Snippet
Calling Code Snippet: