natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.8k stars 591 forks source link

Cannot use lumberjack in Go WebServer App? #25

Closed duongphuhiep closed 8 years ago

duongphuhiep commented 8 years ago

"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 commented 8 years ago

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 commented 8 years ago

YES great! thank you very much

pchico83 commented 3 years ago

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

natefinch commented 3 years ago

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.