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

Is this async safe? #29

Closed
ghost opened this issue Dec 19, 2017 · 2 comments
Closed

Is this async safe? #29

ghost opened this issue Dec 19, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 19, 2017

I am working on a project involving many concurrent services that all require some manner of logging on their own. So far I have been using Zerolog since I love the API it provides and the performance seems to be very good. I have however been noticing that oftentimes I will not see logs from goroutines etc. Is this package safe for concurrent use? Right now I use a single logger instance with is passed to other services using logger.With().Str("service", "example").Logger() and a pointer...

@rs
Copy link
Owner

rs commented Dec 20, 2017

As described in Logger doc:

A Logger represents an active logging object that generates lines of JSON output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. There is no guaranty on access serialization to the Writer. If your Writer is not thread safe, you may consider a sync wrapper.

So if your writer is a file writer in O_APPEND mode, on most OS it's gonna be thread safe as write syscall is atomic in this case. This applies to stdout/err if redirected into a file.

@ghost
Copy link
Author

ghost commented Dec 20, 2017 via email

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

1 participant