Skip to content

Commit 5ce295c

Browse files
authored
Merge pull request #38154 from windsonsea/syslog
[zh] sync cluster-administration/system-logs.md
2 parents 905fa0c + 1508b7b commit 5ce295c

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

content/zh-cn/docs/concepts/cluster-administration/system-logs.md

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ weight: 80
1717
<!--
1818
System component logs record events happening in cluster, which can be very useful for debugging.
1919
You can configure log verbosity to see more or less detail.
20-
Logs can be as coarse-grained as showing errors within a component, or as fine-grained as showing step-by-step traces of events (like HTTP access logs, pod state changes, controller actions, or scheduler decisions).
20+
Logs can be as coarse-grained as showing errors within a component, or as fine-grained as showing
21+
step-by-step traces of events (like HTTP access logs, pod state changes, controller actions, or
22+
scheduler decisions).
2123
-->
2224
系统组件的日志记录集群中发生的事件,这对于调试非常有用。
2325
你可以配置日志的精细度,以展示更多或更少的细节。
@@ -34,16 +36,16 @@ generates log messages for the Kubernetes system components.
3436
3537
For more information about klog configuration, see the [Command line tool reference](/docs/reference/command-line-tools-reference/).
3638
-->
37-
klog 是 Kubernetes 的日志库。
38-
[klog](https://github.com/kubernetes/klog)
39+
klog 是 Kubernetes 的日志库。
40+
[klog](https://github.com/kubernetes/klog)
3941
为 Kubernetes 系统组件生成日志消息。
4042

4143
有关 klog 配置的更多信息,请参见[命令行工具参考](/zh-cn/docs/reference/command-line-tools-reference/)
4244

4345
<!--
44-
Kubernetes is in the process of simplifying logging in its components. The
45-
following klog command line flags [are
46-
deprecated](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components)
46+
Kubernetes is in the process of simplifying logging in its components.
47+
The following klog command line flags
48+
[are deprecated](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components)
4749
starting with Kubernetes 1.23 and will be removed in a future release:
4850
-->
4951
Kubernetes 正在进行简化其组件日志的努力。下面的 klog 命令行参数从 Kubernetes 1.23
@@ -63,26 +65,25 @@ Kubernetes 正在进行简化其组件日志的努力。下面的 klog 命令行
6365
- `--stderrthreshold`
6466

6567
<!--
66-
Output will always be written to stderr, regardless of the output
67-
format. Output redirection is expected to be handled by the component which
68-
invokes a Kubernetes component. This can be a POSIX shell or a tool like
69-
systemd.
68+
Output will always be written to stderr, regardless of the output format. Output redirection is
69+
expected to be handled by the component which invokes a Kubernetes component. This can be a POSIX
70+
shell or a tool like systemd.
7071
-->
7172
输出总会被写到标准错误输出(stderr)之上,无论输出格式如何。
7273
对输出的重定向将由调用 Kubernetes 组件的软件来处理。
7374
这一软件可以是 POSIX Shell 或者类似 systemd 这样的工具。
7475

7576
<!--
76-
In some cases, for example a distroless container or a Windows system service,
77-
those options are not available. Then the
77+
In some cases, for example a distroless container or a Windows system service, those options are
78+
not available. Then the
7879
[`kube-log-runner`](https://github.com/kubernetes/kubernetes/blob/d2a8a81639fcff8d1221b900f66d28361a170654/staging/src/k8s.io/component-base/logs/kube-log-runner/README.md)
7980
binary can be used as wrapper around a Kubernetes component to redirect
8081
output. A prebuilt binary is included in several Kubernetes base images under
8182
its traditional name as `/go-runner` and as `kube-log-runner` in server and
8283
node release archives.
8384
-->
8485
在某些场合下,例如对于无发行主体的(distroless)容器或者 Windows 系统服务,
85-
这些替代方案都是不存在的。那么你可以使用
86+
这些替代方案都是不存在的。那么你可以使用
8687
[`kube-log-runner`](https://github.com/kubernetes/kubernetes/blob/d2a8a81639fcff8d1221b900f66d28361a170654/staging/src/k8s.io/component-base/logs/kube-log-runner/README.md)
8788
可执行文件来作为 Kubernetes 的封装层,完成对输出的重定向。
8889
在很多 Kubernetes 基础镜像中,都包含一个预先构建的可执行程序。
@@ -113,7 +114,7 @@ This table shows how `kube-log-runner` invocations correspond to shell redirecti
113114
114115
An example of the traditional klog native format:
115116
-->
116-
### klog 输出
117+
### klog 输出 {#klog-output}
117118

118119
传统的 klog 原生格式示例:
119120

@@ -134,13 +135,14 @@ which has a line break.
134135
<!--
135136
### Structured Logging
136137
-->
137-
### 结构化日志
138+
### 结构化日志 {#structured-logging}
138139

139140
{{< feature-state for_k8s_version="v1.23" state="beta" >}}
140141

141142
{{< warning >}}
142143
<!--
143-
Migration to structured log messages is an ongoing process. Not all log messages are structured in this version. When parsing log files, you must also handle unstructured log messages.
144+
Migration to structured log messages is an ongoing process. Not all log messages are structured in
145+
this version. When parsing log files, you must also handle unstructured log messages.
144146
145147
Log formatting and value serialization are subject to change.
146148
-->
@@ -151,17 +153,18 @@ Log formatting and value serialization are subject to change.
151153
{{< /warning>}}
152154

153155
<!--
154-
Structured logging introduces a uniform structure in log messages allowing for programmatic extraction of information. You can store and process structured logs with less effort and cost.
155-
The code which generates a log message determines whether it uses the traditional unstructured klog output
156-
or structured logging.
156+
Structured logging introduces a uniform structure in log messages allowing for programmatic
157+
extraction of information. You can store and process structured logs with less effort and cost.
158+
The code which generates a log message determines whether it uses the traditional unstructured
159+
klog output or structured logging.
157160
-->
158161
结构化日志记录旨在日志消息中引入统一结构,以便以编程方式提取信息。
159162
你可以方便地用更小的开销来处理结构化日志。
160163
生成日志消息的代码决定其使用传统的非结构化的 klog 还是结构化的日志。
161164

162165
<!--
163-
The default formatting of structured log messages is as text, with a format that
164-
is backward compatible with traditional klog:
166+
The default formatting of structured log messages is as text, with a format that is backward
167+
compatible with traditional klog:
165168
-->
166169
默认的结构化日志消息是以文本形式呈现的,其格式与传统的 klog 保持向后兼容:
167170

@@ -195,25 +198,25 @@ second line.}
195198
<!--
196199
### Contextual Logging
197200
-->
198-
### 上下文日志
201+
### 上下文日志 {#contextual-logging}
199202

200203
{{< feature-state for_k8s_version="v1.24" state="alpha" >}}
201204

202205
<!--
203206
Contextual logging builds on top of structured logging. It is primarily about
204207
how developers use logging calls: code based on that concept is more flexible
205208
and supports additional use cases as described in the [Contextual Logging
206-
KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging).
209+
KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging).
207210
-->
208211
上下文日志建立在结构化日志之上。
209212
它主要是关于开发人员如何使用日志记录调用:基于该概念的代码将更加灵活,
210-
并且支持在[结构化日志 KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging)
213+
并且支持在[结构化日志 KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging)
211214
中描述的额外用例。
212215

213216
<!--
214217
If developers use additional functions like `WithValues` or `WithName` in
215218
their components, then log entries contain additional information that gets
216-
passed into functions by their caller.
219+
passed into functions by their caller.
217220
-->
218221
如果开发人员在他们的组件中使用额外的函数,比如 `WithValues``WithName`
219222
那么日志条目将会包含额外的信息,这些信息会被调用者传递给函数。
@@ -224,7 +227,7 @@ disabled by default. The infrastructure for this was added in 1.24 without
224227
modifying components. The
225228
[`component-base/logs/example`](https://github.com/kubernetes/kubernetes/blob/v1.24.0-beta.0/staging/src/k8s.io/component-base/logs/example/cmd/logger.go)
226229
command demonstrates how to use the new logging calls and how a component
227-
behaves that supports contextual logging.
230+
behaves that supports contextual logging.
228231
-->
229232
目前这一特性是由 `StructuredLogging` 特性门控所控制的,默认关闭。
230233
这个基础设施是在 1.24 中被添加的,并不需要修改组件。
@@ -271,15 +274,17 @@ I0404 18:03:31.171962 452150 logger.go:95] "another runtime" duration="1m0s"
271274
<!--
272275
### JSON log format
273276
-->
274-
### JSON 日志格式
277+
### JSON 日志格式 {#json-log-format}
275278

276279
{{< feature-state for_k8s_version="v1.19" state="alpha" >}}
277280

278281
{{< warning >}}
279282
<!--
280-
JSON output does not support many standard klog flags. For list of unsupported klog flags, see the [Command line tool reference](/docs/reference/command-line-tools-reference/).
283+
JSON output does not support many standard klog flags. For list of unsupported klog flags, see the
284+
[Command line tool reference](/docs/reference/command-line-tools-reference/).
281285
282-
Not all logs are guaranteed to be written in JSON format (for example, during process start). If you intend to parse logs, make sure you can handle log lines that are not JSON as well.
286+
Not all logs are guaranteed to be written in JSON format (for example, during process start).
287+
If you intend to parse logs, make sure you can handle log lines that are not JSON as well.
283288
284289
Field names and JSON serialization are subject to change.
285290
-->
@@ -298,6 +303,7 @@ Example of JSON log format (pretty printed):
298303
-->
299304
`--logging-format=json` 参数将日志格式从 klog 原生格式改为 JSON 格式。
300305
JSON 日志格式示例(美化输出):
306+
301307
```json
302308
{
303309
"ts": 1580306777.04728,
@@ -322,12 +328,13 @@ Keys with special meaning:
322328
List of components currently supporting JSON format:
323329
-->
324330
具有特殊意义的 key:
331+
325332
* `ts` - Unix 时间风格的时间戳(必选项,浮点值)
326333
* `v` - 精细度(仅用于 info 级别,不能用于错误信息,整数)
327334
* `err` - 错误字符串(可选项,字符串)
328335
* `msg` - 消息(必选项,字符串)
329336

330-
当前支持JSON格式的组件列表
337+
当前支持 JSON 格式的组件列表
331338

332339
* {{< glossary_tooltip term_id="kube-controller-manager" text="kube-controller-manager" >}}
333340
* {{< glossary_tooltip term_id="kube-apiserver" text="kube-apiserver" >}}
@@ -337,10 +344,11 @@ List of components currently supporting JSON format:
337344
<!--
338345
### Log verbosity level
339346
340-
The `-v` flag controls log verbosity. Increasing the value increases the number of logged events. Decreasing the value decreases the number of logged events.
341-
Increasing verbosity settings logs increasingly less severe events. A verbosity setting of 0 logs only critical events.
347+
The `-v` flag controls log verbosity. Increasing the value increases the number of logged events.
348+
Decreasing the value decreases the number of logged events. Increasing verbosity settings logs
349+
increasingly less severe events. A verbosity setting of 0 logs only critical events.
342350
-->
343-
### 日志精细度级别
351+
### 日志精细度级别 {#log-verbosity-level}
344352

345353
参数 `-v` 控制日志的精细度。增大该值会增大日志事件的数量。
346354
减小该值可以减小日志事件的数量。增大精细度会记录更多的不太严重的事件。
@@ -356,7 +364,7 @@ that do not run in a container. For example:
356364
* The kubelet and {{<glossary_tooltip term_id="container-runtime" text="container runtime">}}
357365
do not run in containers.
358366
-->
359-
### 日志位置
367+
### 日志位置 {#log-location}
360368

361369
有两种类型的系统组件:运行在容器中的组件和不运行在容器中的组件。例如:
362370

@@ -377,7 +385,7 @@ The `logrotate` tool rotates logs daily, or once the log size is greater than 10
377385
容器中的系统组件总是绕过默认的日志记录机制,写入 `/var/log` 目录下的 `.log` 文件。
378386
与容器日志类似,你应该轮转 `/var/log` 目录下系统组件日志。
379387
`kube-up.sh` 脚本创建的 Kubernetes 集群中,日志轮转由 `logrotate` 工具配置。
380-
`logrotate` 工具,每天或者当日志大于 100MB 时,轮转日志。
388+
`logrotate` 工具,每天或者当日志大于 100MB 时,轮转日志。
381389

382390
## {{% heading "whatsnext" %}}
383391

0 commit comments

Comments
 (0)