On Day #5 a small entry about getting logs of a pod.
Everyone knows and uses logging. My favourite one is the println in the code, but of course it is not the best. One can much better. In OpenShift, all the logs should be printed out to standard output. Then they can be collected for further processing and indexing.
Getting the logs is straightforward: oc logs <pod-name>
Launching via npm...
npm info it worked if it ends with ok
npm info using email@example.com
npm info using firstname.lastname@example.org
npm info prestart email@example.com
npm info start firstname.lastname@example.org
> email@example.com start /opt/app-root/src
> node server.js
Server running on http://0.0.0.0:8080
These are the first lines logged after starting the nodejs pod.
The command comes with just a few, but very useful parameters.
oc logs --timestamps <pod> – will extend the log output with the timestamp, which can be quite useful if you used println for “logging”
oc logs <pod> -c <container> – gives you logs from specific container in the pod. This parameter is required if you have multiple containers in the pod.
oc logs --since=1h <pod> – print out logs only from last hour. Isn’t this useful when an application produces lots of logs? You can use other units like 10m or 30s.
oc logs --tail=10 <pod> – display last 10 messages that were logged.
Of course you can mix them to get a better overview on what was happening with your application and when.
Check out the help from the command with oc logs --help . And anyway do it often for any command you use, maybe you discover something useful that I omitted.
The commands were executed using minishift and the following client/server versions of OpenShift.
Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.
As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.