Not able to print logs to Tomcat's CATALINA_BASE by using log4j2

Viewed 469

I have update our code from log4j to log4j 2.17.1 And I want to stored the log file to servers under the Apache tomcat. I am using the log4j2.properties mentioned below.

enter image description here

When I run the code, then the logs file is printed in under code structure(see in below attached screenshot)but I want to print the logs file in QA-Servers under apache tomcat.

enter image description here

Please help me to solve the issue.

1 Answers

TL;DR: use ${sys:catalina.base}.

The property substitution in Log4j 2.x differs from Log4j 1.x (cf. documentation). The most prominent change is that:

  • in Log4j 1.x ${catalina.base} is looked up in Java system properties and, if the system property does not exist, in the configuration file,
  • in Log4j 2.x ${catalina.base} is looked up only in the configuration file.

In both cases if the property can not be resolved the placeholder is left unchanged.

In Log4j 2.x all external property lookups must be prefixed using an appropriate prefix. The exact equivalent of Log4j 1.x behavior is ${sys:catalina.base}. Therefore you can use:

# Fallback
property.catalina.base=.
appender.rolling.fileName=${sys:catalina.base}/logs/aseq_wiptmobile_qa-1.applog
Related