How to aggregate application logs

Hello,

I’m trying to understand how to aggregate application logs. For example, say that I have a microservice deployed in Tomcat inside a container. There are four different files generated in the container - access.log, tomcat.log, catalina.out and application.log (log4j output).

I read through the information on this page Logging Architecture - Kubernetes. Is “Sidecar container with a logging agent” the best option for my use case?

Is it possible to fetch pod labels (e.g.: version) and add it to each line? If it is doable, use a logging agent like fluentd? (I just want to know the direction I should take).

Thanks,
Satish

2 Likes

Hope this example helps,

apiVersion: v1
kind: Pod
metadata:
  name: webserver
spec:
  volumes:
    - name: shared-logs
      emptyDir: {}

  containers:
    - name: nginx
      image: nginx
      volumeMounts:
        - name: shared-logs
          mountPath: /var/log/

    - name: sidecar-container
      image: busybox
      command: ["sh","-c","tail -n+1 -f /var/log/app.log"]
      volumeMounts:
        - name: shared-logs
          mountPath: /var/log/