-
Notifications
You must be signed in to change notification settings - Fork 41.3k
Description
What happened?
The klog.InfoS
output was meant to machine readable. In particular it should be possible to split the log output into individual messages.
The argument in kubernetes/klog#268 (comment) was that the klog header can be used to split the output, the same way as current log parsers already do it (backwards compatibility).
That approach does not work when a struct gets logged as value in a key/value pair and that struct contains multi-line data which contains klog headers.
What did you expect to happen?
One of the following would solve the problem:
- document how values are logged in text mode and update Kubernetes log parsers accordingly so that they handle corner cases correctly
- quote structs (but not simple types like ints) - this is actually what's currently in the KEP, it's just wasn't implemented at the end
- switch to a different text format with indention (structured logging: support log messages with line breaks klog#268)
How can we reproduce it (as minimally and precisely as possible)?
type MyStruct struct {
Name string
Data string
internal int
}
func main() {
klog.InitFlags(nil)
flag.Parse()
logData := MyStruct{
Name: "log output from some program",
Data: `I0000 12:00:00.000000 123456 main.go:42] Starting
E0000 12:00:01.000000 123456 main.go:43] Failed for some reason
`,
}
klog.V(0).InfoS("using InfoS", "logData", logData)
}
This currently prints:
I1115 19:05:02.598278 142908 structured_logging.go:65] "using InfoS" logData={Name:log output from some program Data:I0000 12:00:00.000000 123456 main.go:42] Starting
E0000 12:00:01.000000 123456 main.go:43] Failed for some reason
internal:0}
Anything else we need to know?
IMHO text output does not need to be machine-readable, so I favor the third solution because it also addresses #104868 without reverting to non-structured logging.
Kubernetes version
1.23 and older
Cloud provider
n/a
OS version
No response
Install tools
n/a
Container runtime (CRI) and and version (if applicable)
No response
Related plugins (CNI, CSI, ...) and versions (if applicable)
No response