如何在golang中将消息记录到控制台和文件?

I can direct all messages to log.txt file:

logFile, err := os.OpenFile("log.txt", os.O_CREATE | os.O_APPEND | os.O_RDWR, 0666)
if err != nil {
    panic(err)
}
log.SetOutput(logFile)

But how can I get log messages in console too?

Use an 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)