I have hundreds of routines writing to a log file using log.Println ()
I use log.Println to write to the 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) {
Is my approach right? Or should I use the channel to make sure that only one process registers to the file at a time or takes care of it in its own way by the log folder?
Also does the log package take care of buffering or write directly to a file?
logging file-io go buffer
Rahul prasad
source share