Skip to main content
Version: Deploy 24.1

Enable File Logging

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

By default, containers don't have file logging enabled to store the logs created by the container applications. In Deploy, logback.xml file is used for logging. Enabling file logging typically refers to configuring a Deploy 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.

To Enable File Logging

Central Configuration

  1. Get the logback.xml configuration from the container.

    kubectl cp digitalaidai-xld-digitalai-deploy-cc-server-0:conf/logback.xml logback.xml

  2. CentralConfiguration has file logging configured but if you wisht to make changes, edit the logback.xml: vi logback.xml.

  3. Create a patch file that has to be updated from the logback configuration.

c=$(cat logback.xml) \
yq -n '.spec.extraConfiguration.conf_logback.content = strenv(c)' \
> xl-deploy-conf-patch.yaml
  1. Update the configuration patch file with vi xl-deploy-conf-patch.yaml, and specify the location where logback.xml has to be mounted
spec:
centralConfiguration:
extraConfiguration:
conf_logback:
path: "conf/logback.xml"
cpntent: |
...
  • Additionally, the log directory can be mounted to a persistent volume which can already exist in the cluster, for demonstration purposes we will create an emptyDir volume
spec:
centralConfiguration:
...
extraVolumes:
- name: log
emptyDir: {}
extraVolumeMounts:
- name: log
mountPath: /opt/xebialabs/central-configuration-server/log
subPath: log
  • When logging to a file, consider your logging configurations and storage capacity. If left unchecked, the storage can be exhausted quickly.
  1. Apply the file to update the configuration.
kubectl patch -n digitalai digitalaideploys.xld.digital.ai dai-xld 
\--type=merge --patch-file xl-deploy-conf-patch.yaml
  1. Restart the Deploy pods.
kubectl delete sts dai-xld-digitalai-deploy-master -n digitalai
kubectl delete sts dai-xld-digitalai-deploy-worker -n digitalai
  1. Check the final configuration.
  • CR contains the changes that were made. kubectl get Digitalaideploys dai-xld -o yaml -n digitalai

  • Pods will have the additional fields like volume mounts. kubectl get pod dai-xld-digitalai-deploy-master-0 -o yaml -n digitalai

  • Pods uses the new configuration.

kubectl exec -it sts/dai-xld-digitalai-deploy-master -n digitalai \
-- cat /opt/xebialabs/xl-deploy-server/conf/logback.xml

Worker

  1. Get the logback.xml configuration from the container.

    kubectl cp digitalai/dai-xld-digitalai-deploy-worker-0:conf/logback.xml logback.xml

  2. Edit the logback.xml by adding a file appender and include it (appender-ref) in the desired loggers, for example:

Note: If you wish to back up your old configuration → cp logback.xml logback.xml_backup

<configuration>
...
<!-- file log -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>log/xl-deploy-${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>

POD_NAME is a system variable that the pods have configured.

  1. Create a patch file to update the logback configuration.
    c=$(cat logback.xml) \
yq -n '.spec.worker.extraConfiguration.conf_logback.content = strenv(c)' \

> xl-deploy-conf-patch.yaml
  1. Update the configuration patch file vi xl-deploy-conf-patch.yaml.

Specify the location where logback.xml to be mounted.

spec:
worker:
extraConfiguration:
conf_logback:
path: "conf/logback.xml"
content: |
...

Additionally, the log directory can be mounted on a persistent volume that may already exist in the cluster. For demonstration purposes we create an emptyDir volume.

spec:
worker:
...
extraVolumes:
- name: log
emptyDir: {}
extraVolumeMounts:
- name: log
mountPath: /opt/xebialabs/deploy-task-engine/log
subPath: log
  • When logging to a file, consider your logging configurations and storage capacity. If left unchecked, the storage can be exhausted quickly.
  1. Apply the file to update the configuration.
kubectl patch -n digitalai digitalaideploys.xld.digital.ai dai-xld \
--type=merge --patch-file xl-deploy-conf-patch.yaml
  1. Restart the Deploy pods.

kubectl delete sts dai-xld-digitalai-deploy-worker -n digitalai

  1. Check the final configuration.
  • CR contains the changes that were made.
 kubectl get Digitalaideploys dai-xld -o yaml -n digitalai
  • Pods will have the additional fields such as environment variables, volume mounts, and so on.
kubectl get pod dai-xld-digitalai-deploy-worker-0 -o yaml -n digitalai

  • Pods uses the new configuration.
kubectl exec -it sts/dai-xld-digitalai-deploy-worker -n digitalai \
-- cat /opt/xebialabs/deploy-task-engine/conf/logback.xml