You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributors/devel/sig-instrumentation/logging.md
+48-5Lines changed: 48 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,16 +39,36 @@ As per the comments, the practical default level is V(2). Developers and QE
39
39
environments may wish to run at V(3) or V(4). If you wish to change the log
40
40
level, you can pass in `-v=X` where X is the desired maximum level to log.
41
41
42
-
## Logging header formats
42
+
## Logging Formats
43
43
44
-
An example logging message is
44
+
Kubernetes supports multiple logging formats to allow users flexibility in picking a format that best matches their needs.
45
+
As new features and logging formats are proposed, we expect that the Kubernetes community might find itself in disagreement about what formats and features should be officially supported.
46
+
This section will serve as a developer documentation describing high level goals of each format, giving a holistic vision of logging options and allowing the community to resolve any future disagreement when making changes.
47
+
48
+
### Text logging format
49
+
50
+
* Default format in Kubernetes.
51
+
* Purpose:
52
+
* Maintain backward compatibility with klog format.
53
+
* Human-readable
54
+
* Development
55
+
* Features:
56
+
* Minimal support for structured metadata - required to maintain backward compatibility.
57
+
* Marshals object using fmt.Stringer interface allowing to provide a human-readable reference. For example `pod="kube-system/kube-dns"`.
58
+
* Support for multi-line strings with actual line breaks - allows dumping whole yaml objects for debugging.
59
+
60
+
Logs written using text format will always have standard header, however message format differ based on whether string formatting (Infof, Errorf, ...) or structured logging method was used to call klog (InfoS, ErrorS).
61
+
62
+
Examples, first written using Infof, in second InfoS was used.
45
63
```
46
-
I0528 19:15:22.737538 47512 logtest.go:52] msg...
64
+
I0528 19:15:22.737538 47512 logtest.go:52] Pod kube-system/kube-dns status was updated to ready
65
+
I0528 19:15:22.737538 47512 logtest.go:52] "Pod status was updated" pod="kube-system/kube-dns" status="ready"
47
66
```
48
67
49
-
This log line have this form:
68
+
Explanation of header:
50
69
```
51
-
Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
70
+
Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
71
+
52
72
where the fields are defined as follows:
53
73
L A single character, representing the log level (eg 'I' for INFO)
54
74
mm The month (zero padded; ie May is '05')
@@ -59,4 +79,27 @@ where the fields are defined as follows:
59
79
line The line number
60
80
msg The user-supplied message
61
81
```
82
+
62
83
See more in [here](https://github.com/kubernetes/klog/blob/9ad246211af1ed84621ee94a26fcce0038b69cd1/klog.go#L581-L597)
84
+
85
+
### JSON logging format
86
+
87
+
* Requires passing `--logging-format=json` to enable
88
+
* Purpose:
89
+
* Provide structured metadata in efficient way.
90
+
* Optimized for efficient log consumption, processing and querying.
91
+
* Machine-readable
92
+
* Feature:
93
+
* Full support for structured metadata, using `logr.MarshalLog` when available.
94
+
* Multi-line strings are quoted to fit into a single output line.
95
+
96
+
Example:
97
+
```json
98
+
{"ts": 1580306777.04728,"v": 4,"msg": "Pod status was updated","pod":{"name": "kube-dns","namespace": "kube-system"},"status": "ready"}
99
+
```
100
+
101
+
Keys with special meaning:
102
+
* ts - timestamp as Unix time (required, float)
103
+
* v - verbosity (only for info and not for error messages, int)
0 commit comments