how to set system properties before log4j2 load it's configuration?

1.8k views Asked by At

I am using log4j2-beta09.jar in a servlet 3.0+ enviroment. i hope use lookups like ${sys:logPath} in log4j2.xml,so i can set system properties.but the offical site says "The Log4j 2 Core JAR file is a web-fragment configured to order before any other web fragments in your application",so it will not replace the ${sys:logPath} variables. how to set system properties before log4j2 load it's configuration?

1

There are 1 answers

0
Remko Popma On

One way would be to change the configuration for your web container. Usually a web container has a way to set global system properties.

If you don't have control over the container config, or if you need different system properties for different web applications, you could simply call System.setProperty(name, value) when your web application initializes. The tricky part here is to ensure the system properties are set before loading any classes that call LogManager.getLogger() as part of their static field initialization.