Reputation: 7581
My Spring boot application on Redhat/Openshift uses the shown log4j2.xml file.
The issue is that I cannot find the application log file.
My questions are:
I was adviced to use this in de application-openshift.properties file. Leaving these lines out has no consequences.
logging.file = ${OPENSHIFT_DATA_DIR}/logs/app.log
logging.level = INFO
My src/main/resources/log4j2.xml file contains the following. I configured it also for Console for local testing. Yes, later I could distinguish per environment (not for now).
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="File" fileName="logs/app2.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="File" />
</Root>
<Logger name="nl.xyz.mod" level="debug" additivity="false">
<AppenderRef ref="File" />
</Logger>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="nl.xyz.mod" level="info" additivity="false">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
</Configuration>
Upvotes: 2
Views: 2479
Reputation: 7581
Finally solved it!
The change in the log4j2.xml file is marked with ** ... ***.
You can specify a good target for the log file via an OpenShift environment variable. Within the log4j2.xml file you can specify this via ${env:OPENSHIFT_DATA_DIR}.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<!-- ** location of the file is: ${env:OPENSHIFT_DATA_DIR}/logs/app2.log" ** -->
<File name="File" fileName="${env:OPENSHIFT_DATA_DIR}/logs/app2.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="File" />
</Root>
<Logger name="nl.deholtmans.tjm1706" level="debug" additivity="false">
<AppenderRef ref="File" />
</Logger>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="nl.deholtmans.tjm1706b" level="info" additivity="false">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
</Configuration>
Upvotes: 2