<p>I am writing an Operator for Kubernetes using the Operator SDK and have a question about logging (I am still rather new to Go).</p>
<p>I have setup a logger in my controller that I have attached a UUID to as a Trace ID</p>
<pre><code>func (r *MyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    myLog = log.FromContext(ctx).WithValues(&quot;traceID&quot;, uuid.NewUUID())
    myCtx := log.IntoContext(ctx, myLog)
</code></pre>
<p>However I have a Library that is setup at the same time as the controllers and passed in via the struct.</p>
<pre><code>type MyReconciler struct {
    MyBase
    MyClient MyGreatClient
}
</code></pre>
<p>And each method on the client take the ctx as a parameter.</p>
<p>As I want to use the logger in the ctx as it contains my trace ID do I need to add this line to every method in the client or is there a better way to do it?</p>
<pre><code>func (mgc *MyGreatClient) SomethingExists(ctx context.Context, something string) bool {
    myGreatClientLog = log.FromContext(ctx).WithName(&quot;MyGreatClient&quot;)
    myGreatClientLog.Info(&quot;Checking Something Exists&quot;, &quot;Something&quot;, something)
</code></pre>
<p>Is there a better way to achieve what I am wanting to do? It doesn't appear that <code>&quot;sigs.k8s.io/controller-runtime/pkg/log&quot;</code> (of type <code>logr.Logger</code>) supports just logging a context like zap.</p>
<pre><code> myappcontex.Logger(ctx).Info(&quot;did something awesome&quot;)
</code></pre>
<p>Any help on doing this the idiomatic way is appreciated</p>

<p>Not at all sure of this answer and I too wonder why logging and logging sinks are built so complex (refer <a href="https://dave.cheney.net/2015/11/05/lets-talk-about-logging" rel="nofollow noreferrer">https://dave.cheney.net/2015/11/05/lets-talk-about-logging</a> which I found reffered in logr <a href="https://pkg.go.dev/github.com/go-logr/logr@v0.3.0" rel="nofollow noreferrer">https://pkg.go.dev/github.com/go-logr/logr@v0.3.0</a> !);</p>
<p>This is how I logged in a generated <code>kubebuilder</code> operator controller</p>
<pre><code>log.Log.Info(&quot;Pod Image is set&quot;, &quot;PodImageName&quot;, testOperator.Spec.PodImage)
</code></pre>
<p>Ouput-</p>
<pre><code>1.6611775636957748e+09  INFO    Pod Image is set        {&quot;PodImageName&quot;: &quot;alexcpn/run_server:1.2&quot;}
</code></pre>
<p>and with this</p>
<pre><code>log.FromContext(ctx).Info(&quot;Pod Image is &quot;, &quot;PodImageName&quot;, testOperator.Spec.PodImage)
</code></pre>
<p>Ouput is</p>
<pre><code>1.6611801111484244e+09  INFO    Pod Image is    {&quot;controller&quot;: &quot;testoperartor&quot;, &quot;controllerGroup&quot;: &quot;grpcapp.mytest.io&quot;, &quot;controllerKind&quot;: &quot;Testoperartor&quot;, &quot;testoperartor&quot;: {&quot;name&quot;:&quot;testoperartor-sample&quot;,&quot;namespace&quot;:&quot;default&quot;}, &quot;namespace&quot;: &quot;default&quot;, &quot;name&quot;: &quot;testoperartor-sample&quot;, &quot;reconcileID&quot;: &quot;ffa3a957-c14f-4ec9-8cf9-767c38fc26ee&quot;, &quot;PodImageName&quot;: &quot;alexcpn/run_server:1.2&quot;}
</code></pre>
<p>The controller uses Golang Logr</p>
<p><code>All logging in controller-runtime is structured, using a set of interfaces defined by a package called logr (https://pkg.go.dev/github.com/go-logr/logr). The sub-package zap provides helpers for setting up logr backed by Zap (go.uber.org/zap) </code> <a href="https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log#DelegatingLogSink" rel="nofollow noreferrer">https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log#DelegatingLogSink</a></p>
<p>And I can see that it sets Zap logging in main</p>
<pre><code>ctrl.SetLogger(zap.New(zap.UseFlagOptions(&amp;opts)))
</code></pre>
