I have hundreds of subroutines writing into log file using log.Println()
I am using log.Println to write into error.log file.
func main() {
e, err := os.OpenFile("error.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Printf("error opening file: %v", err)
os.Exit(1)
}
defer e.Close()
errLog := log.New(e, ">>>", log.Ldate|log.Ltime)
for i:=0; i<500; i++ {
go worker(errLog)
}
}
func worker(errLog log.Logger) {
// Do some work
errLog.Println("Hello world!!!")
}
Is my approach correct ? Or should I use channel to make sure only one process is logging into file at one time or is it taken care of inherently by log package?
Also does log package takes care of buffering or it directly writes into file?