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

Setting safe: true in the options doesn't guarantee log message getting written #33

Closed
alexyhkim opened this issue May 22, 2014 · 8 comments

Comments

@alexyhkim
Copy link

Added safe: true in the options for the MongoDB transport. Then I log a message and throw an error immediately after. Message shows up in console but not mongo. Adding handleExceptions: true also fails to log anything in mongo. I am considering implementing a custom transport with synchronous logging to mongo. Is this necessary, or am I using the transport incorrectly?

@yurijmikhalevich
Copy link
Member

As mentioned here winston is a multi-transport async logging library for node.js. So, if you want synchronous logging you may want to use another logging library.
By the way, this issue is related to issue winstonjs/winston#228. The key issue seems to be that WritableStreams do not guarantee flushing on process.exit() or unhandled exception.

@yurijmikhalevich
Copy link
Member

Also, look issue #12

@alexyhkim
Copy link
Author

Yep, I realize winston is a multi-transport async logging library for node.js. But what is the point of the {safe: true} option?

@yurijmikhalevich
Copy link
Member

@alexyhkim log method has an optional callback argument, if you pass {safe: true} option, it will be fired only when data was guarantee written.

@alexyhkim
Copy link
Author

When does the callback fire if you don't pass {safe: true}? Because it seemed to fire after data was written without the option as well

@yurijmikhalevich
Copy link
Member

@alexyhkim without {safe: true} mongodb-native callback is fired immediately (after sending data to driver) and thus doesn’t make much sense.

@alexyhkim
Copy link
Author

Oh okay, thank you for the quick replies.

@yurijmikhalevich
Copy link
Member

@alexyhkim you're welcome!

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

No branches or pull requests

2 participants