如何指定Log4J 2.x配置位置? [英] How to specify Log4J 2.x config location?

查看:456
本文介绍了如何指定Log4J 2.x配置位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法手动指定Log4J 2.x log4j2.xml 文件位置(如Log4J中的 DOMConfigurator

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?

推荐答案

您可以使用静态方法 #initialize(String contextName,ClassLoader loader,String configLocation)(see source 这里)在 org.apache.logging.log4j.core.config.Configurator
(您可以为类加载器传递null。)

You could use the static method #initialize(String contextName, ClassLoader loader, String configLocation) (see source here) in org.apache.logging.log4j.core.config.Configurator. (You can pass null for the class loader.)

请注意,此类不是公共API的一部分,因此

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:

-Dlog4j.configurationFile=path/to/log4j2.xml

这篇关于如何指定Log4J 2.x配置位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆