Log4J Configuration via Jvm Argument(S)

log4j configuration via JVM argument(s)?

Do you have a log4j configuration file ? Just reference it using

-Dlog4j.configuration={path to file}

where {path to file} should be prefixed with file:

Edit: If you are working with log4j2, you need to use

-Dlog4j.configurationFile={path to file}

Taken from answer https://stackoverflow.com/a/34001970/552525

Setting log4j properties file via JVM argument - why does order matter?

If you provide anything after naming the JAR file, it is treated as an argument to your main method. For Log4J you actually have to define a property, and this needs to be done before you specify -jar.

User JVM parameter in log4j2 configuration

Take a look at the System Properties Lookup section of the documentation. If you define a variable as system property using -D like this:

-Dapp_home=/home/admin/server

use

${sys:app_home}

in your Log4j 2 configuration to access it.

log4j2.xml loaded but not applied [JVM argument]

Log4j has the ability to automatically configure itself during initialization.
Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to load the configuration.

That 's why my file was detected and loaded without error but not used by spring boot.

The thing I forgot is to tell spring boot where to find the logging configuration file too and for that, I have to add in the application.properties of spring boot :

logging.config= # location of logging config file

And after, everything work well.

Windows - Ant, Log4J2 ConfigurationFile JVM Argument

I managed to get it working with this after finding a similar issue someone had. Just wanted to help others if need be!

<jvmarg value="-Dlog4j.configurationFile=file://${project.dir}/resources/rmiServer/properties/classpath/log4j.properties"/>

E.g. note the file://

spring logging ignores log4j2 configuration file passed as jvm argument

In spring boot the property for the external logging file location is logging.config as described in the manual here:

The various logging systems can be activated by including the
appropriate libraries on the classpath, and further customized by
providing a suitable configuration file in the root of the classpath,
or in a location specified by the Spring Environment property
logging.config.



Related Topics



Leave a reply



Submit