i'm moving from Log4j 1.2 to Log4j 2.8 and am looking for a way to set the location of the property file in my programs. In 1.2, this was done using
PropertyConfigurator.configure("path/to/log4j.properties");
However, reading the documentation, the config via property file in 2.8 seems to be restricted to
a) located in classpath or
b) via System property (see 1)
Since i have some applications where part of the system has its own configuration and needs to load it on demand, i wonder whether there is a way to config the Logmanager during runtime using a properties file?
There is one more way to specify log4j2
configuration file location -
org.apache.logging.log4j.core.config.Configurator.initialize(null, "path/to/log4j2.properties");
Only point of precaution is that the Configurator
class is not part of the public API. So, it might get removed in future version.
Above code is working in log4j2 version 2.8.2
which is latest.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加