1

My environment : JBoss EAP 7 with a "log4j2.xml" in classpath (historic behavior).

I would like to introduce a way to have a (non mandatory) custom log4j2 configuration file (per EAR application) but still use (fall back) to (existing) "log4j2.xml" if the custom configuration file is missing.

To me, the only way to accomplish this was to use composite configuration by using "log4j2.configurationFile" property (within log4j2.component.properties) and set both the "log4j2.xml" and the custom configuration filename (separated by a comma).

But if the custom file is missing, even the generic "log4j2.xml" is ignored.

When looking at log4j2 (v2.12.1) code (https://github.com/apache/logging-log4j2/blob/log4j-2.12.1/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java#L380) I can see that indeed if one config file is missing, none config file (of the list) is used (-> "return null")

Is there a way to accomplish the behavior I want?

Thanks

Benjamin C
  • 119
  • 2
  • 11
  • If you are using Spring, profiles appear to support the behavior you want, [see this SO question](https://stackoverflow.com/questions/35559824/spring-profiles-different-log4j2-configs). – Tim Biegeleisen Oct 11 '19 at 09:42
  • Thank you @TimBiegeleisen but I am not using Spring – Benjamin C Oct 11 '19 at 09:48
  • Why not just tell your user to specify the system property `"log4j.configurationFile"` if they wish to override the provided configuration? See [configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html) page of log4j2 manual. If that's not satisfactory then you could create a [custom ConfigurationFactory](https://logging.apache.org/log4j/2.x/manual/extending.html#ConfigurationFactory) – D.B. Oct 12 '19 at 15:51
  • Thank you @D.B. for your comment. Maybe I was not clear enough. So I have edited my question saying I am using an application server that can be common to several application. And for now all applications were using (by default) the "log4j2.xml" present in the classpath. – Benjamin C Oct 17 '19 at 15:30

0 Answers0