I'm using the handy kubectl logs -l label=value
command to get log from all my pods matching a label. I want to see which pod outputted what log, but only the log text is displayed. Is there a way to control the log format, or a command argument which will let me do this?
kubectl
now has a --prefix
option that allows you to prefix the pod name before the log message.
I use stern to show logs from all pods https://github.com/wercker/stern.
As simple as this:
for pod in $(kubectl get po -l key=value -oname); do echo $pod; kubectl logs $pod; done;
this will fetch the names of the pods by their label, then will one by one print the logs after writing the name of the pod. So, it will look like something like this:
pod1
log
log
log
pod2
log
log
log
...
podn
log
log
log