Skip to main content
Version: Release 24.3

Enable File Logging

This topic explains how to enable file logging in the Kubernetes cluster for Release application.

By default, containers don't have file logging enabled to store the logs created by the container applications. In Release, logback.xml file is used for logging. Enabling file logging typically refers to configuring a Release application running within a Kubernetes cluster to generate log files, and possibly directing those logs to a specific location or storage system. Often, we want to save the log files in a persistent storage space so that even if the container restarts, we can retrieve those logs. In such cases, it's a good idea to name the log file using the same name as the pod that creates the logs.

How to Enable File Logging

  1. Get the logback.xml configuration from the container.
kubectl cp digitalai/dai-xlr-digitalai-release-0:conf/logback.xml logback.xml
  1. Edit the logback.xml by adding a file appender (appender-ref) in the desired loggers.

Note

  • Back up your old configuration by running this command: cp logback.xml logback.xml_backup
  • POD_NAME is a system variable that the pods have configured.
<configuration>
...
<!-- file log -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>log/xl-release-${POD_NAME}.log</file>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] {%mdc} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="${LOGBACK_GLOBAL_LOGGING_LEVEL}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
...
</configuration>
  1. Create a patch file to update the logback configuration.
c=$(cat logback.xml) \
yq -n '.spec.extraConfiguration.conf_logback.content = strenv(c)' \
> xl-release-conf-patch.yaml
  1. Update the configuration patch file by running the following command:
vi xl-release-conf-patch.yaml
  • Specify the location where logback.xml should be mounted.
spec:
extraConfiguration:
conf_logback:
path: "conf/logback.xml"
content: |
...
  • Additionally, the log directory can be mounted to a persistent volume which can already exist in the cluster. For example, create an emptyDir volume.
spec:
...
extraVolumes:
- name: log
emptyDir: {}
extraVolumeMounts:
- name: log
mountPath: /opt/xebialabs/xl-release-server/log
subPath: log
  1. To apply the file to update the configuration, run the following command:
kubectl patch -n digitalai digitalaireleases.xlr.digital.ai dai-xlr \
--type=merge --patch-file xl-release-conf-patch.yaml
  1. Once the pods are restarted, you will see the following changes:
  • CR will contain changes that were made.
kubectl get Digitalaireleases dai-xlr -o yaml -n digitalai
  • Pods will have the additional fields (environment variables, volume mount, and so on).
kubectl get pod dai-xlr-digitalai-release-0 -o yaml -n digitalai
  • Pods will now be using the new configuration.
kubectl exec -it sts/dai-xlr-digitalai-release -n digitalai \
-- cat /opt/xebialabs/xl-release-server/conf/logback.xml