简体   繁体   English

klog 如何记录到标准输出以及文件文件

[英]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.

相关问题 为什么我没有日志? 空 web.stdout.logs? - Why do I have no logs? empty web.stdout.logs? Greengrass V2 生成额外的“stdout”日志 - Greengrass V2 generates extra `stdout` logs 将 Azure 应用服务的 stdout 和 stderr 日志存储到 Azure Blob 存储中 - Store stdout and stderr logs of Azure App Service into Azure Blob Storage 持久卷声明附加到 kube.netes 部署以访问 PVC 中存在的文件,但不应将任何日志写入 PVC? - Persistent volume claim attach to kubernetes deployment to access files present in PVC but should not write any logs to PVC? 如何获取 firebase 的 dSYM 文件 - How to get dSYM files for firebase 如何在 AWS CodePipeline 中添加文件? - How to add files in AWS CodePipeline? 如何将CSV文件导入Firebase - How to import CSV files into Firebase 如何批量更新 Amazon S3 文件上数千个文件的元数据? - How to mass update metadata on thousands of files on Amazon S3 files? 如何比较 golang 中的两个文件? - How can I compare two files in golang? GCP App Engine - 如何提供最新文件 - GCP App Engine - How to serve newest files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM