I would like to know if is possible to filter logs, only showing ERROR Level
kubectl logs -f -n the-namespace the-pod [LOG-LEVEL?] in example ERROR only
I was trying with:
kubectl logs -f -n bci-api the-pod | awk '{ if ($3 == "ERROR") { print } }'
The problem, are there some lines that are continuation of ERROR line and will be hidden!
Is it possible?
Thanks in advance!
According to this documentation there doesn't seem to be a way you can do this. There is a verbosity flag
-vbut that is for the level of verbosity inkubectlitself, not in the logs it is getting for thepods/containers.Then you also have the
--stderrthreshold <SEVERITY>option tokubectlas provided in this doc, but I suspect that is the same thing.Perhaps a better way of handling this would be to set what is called a
logging architecturefor your cluster where you can control which logs the pod actually generates. (read more here) In that way, fetching them fromkubectlwill be probably more desirable.We almost always use a 3rd party centralized logging solution (like fleuntd), outside of k8s for this specific reason. And we simply inject a logging sidecar container to your pods which continuously dumps the logs to this central component. This is a very common design pattern.