# Contextual logging in Kubernetes 1.29: Better troubleshooting and enhanced logging

DevFeed: [Contextual logging in Kubernetes 1.29: Better troubleshooting and enhanced logging](<https://devfeed.tech/articles/contextual-logging-in-kubernetes-1-29-better-troubleshooting-and-enhanced-logging-17570.md>)

Original publisher: [Read original article](<https://www.kubernetes.dev/blog/2023/12/20/contextual-logging/>)

Author: The Kubernetes Authors

Published: 2023-12-20T17:30:00Z

Content type: release

Language: en

Sources: [Kubernetes Contributors Blog](<https://devfeed.tech/sources/kubernetes-contributors-blog.md>)

Topics: [Kubernetes](<https://devfeed.tech/topics/kubernetes.md>), [Logging](<https://devfeed.tech/topics/logging.md>), [Instrumentation](<https://devfeed.tech/topics/instrumentation.md>), [telemetry](<https://devfeed.tech/topics/telemetry.md>)

Tags: [go-test](<https://devfeed.tech/tags/go-test.md>), [instrumentation](<https://devfeed.tech/tags/instrumentation.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [logging](<https://devfeed.tech/tags/logging.md>), [logs](<https://devfeed.tech/tags/logs.md>), [tests](<https://devfeed.tech/tags/tests.md>), [troubleshooting](<https://devfeed.tech/tags/troubleshooting.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

## AI overview

The article announces that Kubernetes contextual logging, introduced in Kubernetes v1.24, has been migrated to kube-scheduler, kube-controller-manager, and some directories. Based on the go-logr API, the feature passes logger instances through callers to support structured logs with additional context, improving troubleshooting and test output in parallel applications.

## Source excerpt

On behalf of the Structured Logging Working Group and SIG Instrumentation , we are pleased to announce that the contextual logging feature introduced in Kubernetes v1.24 has now been successfully migrated to two components (kube-scheduler and kube-controller-manager) as well as some directories. This feature aims to provide more useful logs for better troubleshooting of Kubernetes and to empower developers to enhance Kubernetes. What is contextual logging? Contextual logging is based on the go-logr API. The key idea is that libraries are passed a logger instance by their caller and use that for logging instead of accessing a global logger. The binary decides the logging implementation, not the libraries. The go-logr API is designed around structured logging and supports attaching additional information to a logger. This enables additional use cases: The caller can attach additional information to a logger: WithName adds a "logger" key with the names concatenated by a dot as value WithValues adds key/value pairs When passing this extended logger into a function, and the function uses it instead of the global logger, the additional information is then included in all log entries, without having to modify the code that generates the log entries. This is useful in highly parallel applications where it can become hard to identify all log entries for a certain operation, because the output from different operations gets interleaved. When running unit tests, log output can be associated with the current test. Then, when a test fails, only the log output of the failed test gets shown by go test. That output can also be more verbose by default because it will not get shown for successful tests. Tests can be run in parallel without interleaving their output. One of the design decisions for contextual logging was to allow attaching a logger as value to a context.Context. Since the logger encapsulates all aspects of the intended logging for the call, it is part of the context,