您的位置:首页 > 运维架构

Log4j配置文件被覆盖,log4j.properties无效(检查方法)

2015-03-09 14:25 1186 查看
今天的项目中遇到了log4j.properties日志配置文件不起作用的问题,看了log4j.properties文件是没有语法问题,但是log的配置不起作用。

最后检查是被一个第三方包里面有一个log4j.xml的配置文件。

在log4j.properties和log4j.xml两个文件都存在的时候,log4j框架默认先找log4.xml文件。

怎么确认自己的log4j配置文件时候被第三方包覆盖呢?

可以通过在java命令中添加
-Dlog4j.debug
虚拟机参数来显示log4j加载配置文件的位置。

打印结果如下:

log4j: Trying to find [log4j.xml] using context classloader ContextLoader@client-sso.

log4j: Using URL [jar:file:/F:/maven_dir/com/baidu/unionlogin/1.0/unionlogin-1.0-baidu.jar!/log4j.xml] for automatic log4j configuration.

log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator

log4j: System property is :null

log4j: Standard DocumentBuilderFactory search succeded.

log4j: DocumentBuilderFactory is: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

log4j: debug attribute= "null".

log4j: Ignoring debug attribute.

log4j: reset attribute= "false".

log4j: Threshold ="null".

log4j: Level value for root is [info].

log4j: root level set to INFO

log4j: Class name: [org.apache.log4j.ConsoleAppender]

log4j: Setting property [target] to [System.out].

log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"

log4j: Setting property [conversionPattern] to [%n%-5p:%m %n==> %l%n].

从日志中就能详细指导log4j具体是加载的那个配置文件,找到这个问题后,就好解决啦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: