[Kubernetes] Klog
Updated:
설명
- https://kubernetes.io/ko/docs/concepts/cluster-administration/system-logs/
- 쿠버네티스의 로깅 라이브러리
- 포맷
<klog header> "<message>" <key1>="<value1>" <key2>="<value2>" ...
- 사용법은 glog와 거의 유사
예제
- 코드
package main import ( "errors" "k8s.io/klog/v2" ) func main() { defer klog.Flush() klog.Infof("%s test", "Infof") klog.Warningf("%s test", "Warningf") klog.Errorf("%s test", "Errorf") klog.InfoS("message", "a", "aaa", "1", 111) err := errors.New("error occur") klog.ErrorS(err, "message", "a", "aaa", "1", 111) }
- 결과
I0909 17:17:07.683384 3115 test.go:11] Infof test W0909 17:17:07.683605 3115 test.go:12] Warningf test E0909 17:17:07.683613 3115 test.go:13] Errorf test I0909 17:17:07.683792 3115 test.go:15] "message" a="aaa" 1=111 E0909 17:17:07.683815 3115 test.go:18] "message" err="error occur" a="aaa" 1=111