简体   繁体   中英

How to add log4j2 configuration file as system property?

I have been trying to pass the log configuration url through system property but it is resulting in an error.

ERROR StatusLogger No logging configuration

I have passed the system property as follows:

<sysproperty key="log4j.configurationFile" value="file:${_real_dir}/config/project.log4j2" />

Here project.log4j2 is the configuration file. How should I change the sysproperty key to make this work?

The documentation on this is relatively clear - you need to make the extension of the configuration type match the file format, so the factory can generate the correct configuration parser.

The ConfigurationFactory documentation indicates 4 logging file formats: Json, XML, Yaml and Property file format.

You need to make the file extension for the configuration match the file format, so if your configuration is xml, then make the file extension .xml , etc.

So if the config is in xml, your systemproperty should look like:

<sysproperty key="log4j.configurationFile" value="file:${_real_dir}/config/project.log4j2.xml" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM