Skip to content
gobomb edited this page Jun 29, 2020 · 6 revisions

kubectl 的调试级别(glog)

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

--v=0   Generally useful for this to ALWAYS be visible to an operator.
--v=1   A reasonable default log level if you don’t want verbosity.
--v=2   Useful steady state information about the service and important log messages that may correlate to significant changes in the system. This is the recommended default log level for most systems.
--v=3   Extended information about changes.
--v=4   Debug level verbosity.
--v=6   Display requested resources.
--v=7   Display HTTP request headers.
--v=8   Display HTTP request contents

klog的参数

-logtostderr=false
会写到文件,默认是/tmp目录下
info、error、fatal会写到标准错误
fatal会把堆栈写到标准错误

-logtostderr=true
不会写到文件
info、fatal、error都写到标准错误

-alsologtostderr=true
不会写到文件
info、error、fatal会写到标准错误


-log_dir /to/dir/
输出到该目录的文件下

-logtostderr=false  -log_dir=/to/dir/
会写到文件,不会写到标准错误或输出
-logtostderr=false  -alsologtostderr=true  -log_dir=/to/dir/
会写到文件,也会写到标准错误

-v=3
小于等于-v的值的log会被输出

-v=3 --stderrthreshold=0 -logtostderr=false -log_dir=/to/dir/
-v大于-stderrthreshold才会被同时输出到标准错误,否则只输出到文件

目前自己使用的日志级别(glog)

在使用 k8s 的库的时候,--v=3 就有库输出的 log 了

错误:
glog.Errorf("sth %v",err)

日志:
glog.V(0).Infof("sth %v",info)

0 不符合预期的错误(必须输出)
1 不符合预期的输出
2 符合预期的输出(debug 可用,保证一切正常)
3 符合预期的错误(debug 可用,保证一切正常)
Clone this wiki locally