<p>I'm working on a project that uses the <code>klog library</code> for logging, and I want to be able to write the <code>logs to a **terminal** while being able to write to a **file**</code> for viewing on reboot or downtime.</p>
<p>I tested through the following code, but it can only write to the file and not output at the terminal at the same time</p>
<pre><code>package main

import (
    &quot;flag&quot;
    &quot;k8s.io/klog/v2&quot;
)

func init() {
func init() {
    var fs flag.FlagSet
    klog.InitFlags(&amp;fs)
    fs.Set(&quot;logtostderr&quot;, &quot;false&quot;)
    fs.Set(&quot;log_file_max_size&quot;, &quot;1000&quot;)
    fs.Set(&quot;log_file&quot;, &quot;/home/test/workspace/test/test.log&quot;)
}
}

func main() {
    defer klog.Flush()
    klog.Info(&quot;test&quot;)
}
</code></pre>
<p>How can I get it? I really appreciate any help with this.</p>

moluzhui
<p>If you read the <a href="https://pkg.go.dev/k8s.io/klog/v2#section-documentation" rel="nofollow noreferrer">Klog documentation</a> says that it supports a flag, <code>-alsologtostderr</code>:</p>
<blockquote>
<p><code>-alsologtostderr=false</code><br/>
Logs are written to standard error as well as to files.</p>
</blockquote>
<p>Seems like that would do you.</p>
