我可以将所有消息定向到log.txt文件:
logFile,err := os.OpenFile("log.txt",os.O_CREATE | os.O_APPEND | os.O_RDWR,0666) if err != nil { panic(err) } log.SetOutput(logFile)
但是如何在控制台中获取日志消息呢?
使用
原文链接:https://www.f2er.com/go/187042.htmlio.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)