Skip to main content

Logging

Applications generate many status messages as they do their processing. These can be errors, security events, audit events, or even just normal progress messages. These messages are collected and processed by logging tools so that the application developer can better troubleshoot when things go wrong. This process is particularly useful for microservice applications consisting of hundreds of containers, as the processing is distributed. Coordination of logging output alongside metrics gives application developers key insight into how their application is performing.

Application developers on Section can leverage a wide range of tooling, such as Elastic Kibana, Splunk, Grafana Loki, and more.

  • The Cloud Native Computing Foundation gives a great overview of Logging and the tooling available to assist.
  • Kubectl is a command-line tool you’ll use to control your application on the Section Platform. We use the “kubectl logs” command in the guides below.

Kubectl logs

Logs for your application can be seen by using “kubectl logs”. A few examples of using this command are shown below.

CommandResult
kubectl logs MY_POD# dump pod logs (stdout)
kubectl logs -l name=myLabel# dump pod logs, with label name=myLabel (stdout)
kubectl logs MY_POD --previous# dump pod logs (stdout) for a previous instantiation of a container
kubectl logs MY_POD -c MY_CONTAINER# dump pod container logs (stdout, multi-container case)
kubectl logs -l name=myLabel -c MY_CONTAINER# dump pod logs, with label name=myLabel (stdout)
kubectl logs MY_POD -c MY_CONTAINER --previous# dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
kubectl logs -f MY_POD# stream pod logs (stdout)
kubectl logs -f MY_POD -c MY_CONTAINER# stream all pods logs with label name=myLabel (stdout)# stream pod container logs (stdout, multi-container case)
kubectl logs -f -l name=myLabel --all-containers# stream all pods logs with label name=myLabel (stdout)

Streaming Logs

An interesting usage of “kubectl logs” is to stream logs from your entire application to a destination whereby you can view logs using a cloud-native log viewer such as Splunk, Elastic, etc. Set up a container in Section (one replica at one location), or on any infrastructure of your choice, that runs the following command:

kubectl logs -f deployment/YOUR_APP_NAME --all-containers=true --since=10m

That command says to follow logs for that deployment from the given namespace for all containers for the past 10 minutes. You can also use the service in place of deployment.

You would stream the output of that command into a process that then ships the logs to your destination tooling of choice, such as Elastic, Splunk, etc.