logFile,err := os.OpenFile("log.txt",os.O_CREATE | os.O_APPEND | os.O_RDWR,0666) if err != nil { panic(err) } log.SetOutput(logFile)
但是如何在控制台中获取日志消息呢?
logFile,err := os.OpenFile("log.txt",os.O_CREATE | os.O_APPEND | os.O_RDWR,0666) if err != nil { panic(err) } log.SetOutput(logFile)
但是如何在控制台中获取日志消息呢?
io.MultiWriter
MultiWriter creates a writer that duplicates its writes to all the provided writers,similar to the Unix tee(1) command
mw := io.MultiWriter(os.Stdout,logFile) log.SetOutput(mw)