LoginSignup
7
3

More than 1 year has passed since last update.

Kubernetes の構造化ログのフォーマットについて

Last updated at Posted at 2022-12-14

Kubernetes の構造化ロギングについて

Kubernetes ではロギングライブラリとして klog が使用されています。
https://kubernetes.io/docs/concepts/cluster-administration/system-logs/

そして、Kubernetes 1.23 から構造化ロギングが Beta に昇格して、各コンポーネントのログメッセージの大半が構造化されてロギングされるようになっています。詳細は Kubernetes 1.23: Metrics Changes と SIG Instrumentation の変更内容 をご参照ください。

ログを構造化することで機械が処理しやすくなるので、他システムと連携して活用しやすくなります。なお、現在も移行中で全てのログが構造化されているわけではないので注意が必要です。

構造化ログのフォーマット

構造化ログの形式は以下のようになっています。

<klog header> "<message>" <key1>="<value1>" <key2>="<value2>" ...

以下は構造化ログの例となります。

I1025 00:15:15.525108       1 controller_utils.go:116] "Pod status updated" pod="kube-system/kubedns" status="ready"

公式ドキュメントでは詳細が割愛されていますが、klog header にはログレベルや時刻などのメタデータが含まれています。仕様はドキュメントされておらず、klog のソースコードに直接記載されています。

Log lines have this form:

	Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...

where the fields are defined as follows:

	L                A single character, representing the log level (eg 'I' for INFO)
	mm               The month (zero padded; ie May is '05')
	dd               The day (zero padded)
	hh:mm:ss.uuuuuu  Time in hours, minutes and fractional seconds
	threadid         The space-padded thread ID as returned by GetTID()
	file             The file name
	line             The line number
	msg              The user-supplied message

ログレベルは先頭のアルファベットで表現される仕様です。Info、Warning、Error、Fatal のように各ログレベルの頭文字が使用されて (ソースコード)、その後に Month と Day の4桁数字が続くような形式になっています。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3