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

1/9/2020

enter image description here

but the problem is my application is running before my server started (WebLogic server).

-- Kundan Kumar
environment-variables
hostname
kubernetes
log4j2

1 Answer

1/15/2020

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>
-- rgoers
Source: StackOverflow