How to append kubernetes container id/name to log file in log4j.xml How to append kubernetes container id/name to log file in log4j.xml kubernetes kubernetes

How to append kubernetes container id/name to log file in log4j.xml


Your question seems to be in reference to Log4j 1. Log4j 1 has been end-of-life since August of 2015.

Upgrading to Log4j 2.13.0 would allow you to use the Kubernetes Lookup which would allow you to configure your log file name as:

<File name="MyFile" filename="${path}/app_${k8s:containerName}.${date:MM-dd-yyyy}.log>  <PatternLayout>    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>  </PatternLayout></File>