Is there any way to specify Log4J 2.x log4j2.xml
file location manually (like DOMConfigurator
in Log4J 1.x), without messing with classpath and system properties?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
In Windows, be aware that you need to use a URI with the
log4j.configurationFile
propertyYou could use the static method
#initialize(String contextName, ClassLoader loader, String configLocation)
(see source here) inorg.apache.logging.log4j.core.config.Configurator
. (You can pass null for the class loader.)Be aware that this class is not part of the public API so your code may break with any minor release.
For completeness, you can also specify the location of the configuration file with this system property:
Using the LoggerContext allows to setConfigLocation.
or alternatively
You can initialize like below as well
In each class you can get logger instance as below