Kubernetes 1.24: Structured Logs for Enhanced Clarity
ayedo Redaktion 2 Minuten Lesezeit

Kubernetes 1.24: Structured Logs for Enhanced Clarity

Discover the new features for structured logging in Kubernetes 1.24 and how they can enhance your logs.
kubernetes kubernetes-news event-management

The Working Group for Structured Logging has introduced new features to the logging infrastructure in Kubernetes 1.24. In this article, you’ll learn how developers can leverage these to make log outputs more useful and how they can actively participate in improving Kubernetes.

Structured Logging

The goal of structured logging is to replace C-style formatting and the resulting opaque log strings with log entries that have a clearly defined syntax for separately storing messages and parameters, for instance, as a JSON structure.

When using the traditional klog text output format for structured log calls, strings were originally output with \n escape sequences, unless they were embedded in a structure. For structures, log entries could still span multiple lines, with no clean way to split the log stream into individual entries:

I1112 14:06:35.783529 328441 structured_logging.go:51] “using InfoS” longData={Name:long Data:Multiple lines with quite a bit of text. internal:0} I1112 14:06:35.783549 328441 structured_logging.go:52] “using InfoS with\nthe message across multiple lines” int=1 stringData=“long: Multiple\nlines\nwith quite a bit\nof text.” str=“another value”

Now, the < and > markers are used along with indentation to ensure that splitting at a klog header at the beginning of a line is reliable and the resulting output is human-readable:

I1126 10:31:50.378204 121736 structured_logging.go:59] “using InfoS” longData=< {Name:long Data:Multiple lines with quite a bit of text. internal:0}

I1126 10:31:50.378228 121736 structured_logging.go:60] “using InfoS with\nthe message across multiple lines” int=1 stringData=< long: Multiple lines with quite a bit of text.

str=“another value”

Note that the log message itself is output with quotes. It should be a fixed string identifying a log entry, so line breaks should be avoided there.

Before Kubernetes 1.24, some log calls in the kube-scheduler still used klog.Info for multiline strings to avoid unreadable output. Now, all log calls have been updated to support structured logging.

The new structured logging features in Kubernetes 1.24 provide developers and DevOps teams with the opportunity to significantly enhance the quality of their logs. Use these changes to better monitor your applications and identify issues more quickly. ayedo is happy to support you as a partner in implementing Kubernetes solutions!


Source: Kubernetes Blog

Ähnliche Artikel