How to set Golang's log output back to console?

huangapple go评论67阅读模式
英文:

How to set Golang's log output back to console?

问题

Google Go的log包有一个名为SetOutput的函数,用于将日志输出设置为任何io.Writer。在我设置它进行测试后,我想将输出恢复为标准控制台输出 - 我该如何做到这一点?我在logio包中没有看到任何明显的重置方法。

英文:

Google Go's log package has SetOutput - a function for setting the log output to any io.Writer. After I set it for testing, I would like to revert the output back to the standard console output - how do I do that? I don't see any obvious way of resetting it in the log or io packages.

答案1

得分: 89

对于标准错误输出(默认情况下):

log.SetOutput(os.Stderr)

对于标准输出:

log.SetOutput(os.Stdout)

http://golang.org/src/log/log.go

英文:

For standard error (the default):

log.SetOutput(os.Stderr)

For standard output:

log.SetOutput(os.Stdout)

http://golang.org/src/log/log.go

huangapple
  • 本文由 发表于 2015年6月8日 03:38:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/30697694.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定