Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call logtail.flush() when LogtailTransport (winston) is closed #118

Merged

Conversation

mutaflux
Copy link
Contributor

We started using @logtail/node with winston and noticed that when a winston logger closes, LogtailTransport does not flush buffered messages to logtail. This is especially annoying when trying to log unhandled exceptions that cause the process to exit.

The base winston Transport class accepts a close() callback in the constructor options object, which is called whenever the transport instance is "unpiped" from the logger. This PR wraps any close() callback passed to the constructor of LogtailTransport with the flushing logic.

This PR also adds a unit test for LogtailTransport. This test fails without the changes in the constructor.

Copy link
Member

@PetrHeinz PetrHeinz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mutaflux, and thank you for taking your time with your contribution 🙏

Excellent work on describing the issue, fixing it, and even providing a test 🚀

I've just verified the test fails as expected, and ran lint. I'll release it as v0.4.23 shortly. Thanks again, much appreciated!

@PetrHeinz PetrHeinz merged commit 3ece9f8 into logtail:master Jul 31, 2024
5 checks passed
@PetrHeinz
Copy link
Member

New @logtail/winston released as v0.4.23: https://www.npmjs.com/package/@logtail/winston/v/0.4.23 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants