[英]How klog logs to stdout as well as files files
I'm working on a project that uses the klog library
for logging, and I want to be able to write the logs to a **terminal** while being able to write to a **file**
for viewing on reboot or downtime.我正在开发一个使用
klog library
进行日志记录的项目,我希望能够将logs to a **terminal** while being able to write to a **file**
以在重启或停机时查看.
I tested through the following code, but it can only write to the file and not output at the terminal at the same time我通过以下代码进行了测试,但它只能写入文件而不是同时在终端写入output
package main
import (
"flag"
"k8s.io/klog/v2"
)
func init() {
func init() {
var fs flag.FlagSet
klog.InitFlags(&fs)
fs.Set("logtostderr", "false")
fs.Set("log_file_max_size", "1000")
fs.Set("log_file", "/home/test/workspace/test/test.log")
}
}
func main() {
defer klog.Flush()
klog.Info("test")
}
How can I get it?我怎么才能得到它? I really appreciate any help with this.
我真的很感激这方面的任何帮助。
If you read the Klog documentation says that it supports a flag, -alsologtostderr
:如果您阅读Klog 文档说它支持标志,
-alsologtostderr
:
-alsologtostderr=false
Logs are written to standard error as well as to files.日志被写入标准错误以及文件。
Seems like that would do you.好像你会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.