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

Cannot use lumberjack in Go WebServer App? #25

Closed
duongphuhiep opened this issue Jun 5, 2016 · 4 comments
Closed

Cannot use lumberjack in Go WebServer App? #25

duongphuhiep opened this issue Jun 5, 2016 · 4 comments

Comments

@duongphuhiep
Copy link

duongphuhiep commented Jun 5, 2016

"Lumberjack assumes that only one process is writing to the output files. Using the same lumberjack configuration from multiple processes on the same machine will result in improper behavior."

Is it means that we shouldn't use Lumberjack in Golang WebServer or any Go application with Go routines concurrently write to the log file?

thank you

@natefinch
Copy link
Owner

Oh no no. Lumberjack is totally thread/goroutine safe from a single process. Any number of goroutines can write to it safely. It is only if multiple processes write to it that you can experience problems.

@duongphuhiep
Copy link
Author

YES great! thank you very much

@pchico83
Copy link

@natefinch what would be an alternative if multiple processes write to the same log file? we are facing this issue in windows

@natefinch
Copy link
Owner

Well, you probably shouldn't do that anyway. You can easily get interspersed writes, like one process writes the first half of a log message, then the other process writes the first half of their log message, then both write the second half... and that even assumes that one doesn't just lock the file and exclude the other.

The only way I can think to make that work is to have a third process that both send their log messages to, and it serializes them, and then it handles the log rotation. But it seems easier just to let each process have its own log file.

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

3 participants