I am implementing a logging library using golang. I know that writing logs to file is a slow I/O operation. Then I was thinking of using goroutine to leverage the benefit of the async nature of goroutine. So that the main goroutine will not be blocked by any I/O operation. Recently, I found go library provides a buffered I/O library. I am wondering which way is the best way to implement file logging? Is there any trade off between these two designs?
One goroutine reads from a buffered channel and writes to a buffered writer, other goroutines send logs to that channel.