forked from golang/glog
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structured logging: support log messages with line breaks
The initial structured logging output (almost) always produced a single line per log message, with quoting of strings to represent line breaks as \n. This made the output hard to read (see kubernetes/kubernetes#104868). It was still possible to get line breaks when formatting a value with `%+v` and that ended up emitting line breaks; this was probably not intended. Now the message is never quoted, as in non-structured output. String values are quoted if they contain no line break. If they do, start/end markers delimit the text which appears on its own lines. All additional lines of a structure log message get indented by one space. This makes it obvious where a new log message starts, which is an improvement compared to the traditional format. Traditional output: I1112 14:06:35.783354 328441 structured_logging.go:42] someData printed using InfoF: {hello world 0} I1112 14:06:35.783472 328441 structured_logging.go:43] longData printed using InfoF: {long Multiple lines with quite a bit of text. 0} I1112 14:06:35.783483 328441 structured_logging.go:44] stringData printed using InfoF, with the message across multiple lines: long: Multiple lines with quite a bit of text. Old InfoS output before this commit: I1112 14:06:35.783512 328441 structured_logging.go:50] "using InfoS" someData={Name:hello Data:world internal:0} 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" I1112 14:06:35.783565 328441 structured_logging.go:61] "Did something" item="foobar" I1112 14:06:35.783576 328441 structured_logging.go:63] "This is a full sentence." item="foobar" New InfoS output: I1112 15:01:48.696617 413871 structured_logging.go:50] using InfoS: someData={Name:hello Data:world internal:0} I1112 15:01:48.696646 413871 structured_logging.go:51] using InfoS: ===start of longData=== {Name:long Data:Multiple lines with quite a bit of text. internal:0} ===end of longData=== I1112 15:01:48.696677 413871 structured_logging.go:52] using InfoS with the message across multiple lines: int=1 ===start of stringData=== long: Multiple lines with quite a bit of text. ===end of stringData=== str="another value" I1112 15:01:48.696704 413871 structured_logging.go:61] Did something: item="foobar" I1112 15:01:48.696719 413871 structured_logging.go:63] This is a full sentence. item="foobar"
- Loading branch information
Showing
3 changed files
with
114 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters