开发者社区> 问答> 正文

为什么我的项目中读取不到log42.xml 文件,导致日志不输出呢?报错

项目框架 : maven spring jetty  

今天启动项目时 ,发现报错,错误提示如下 :


ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.
2018-08-01 13:19:07.640:INFO:/:Initializing Spring root WebApplicationContext
{zhijia.praiseme.common.mapper.CCommonLabelMapper.selectList} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{zhijia.praiseme.info.mapper.PInfoMapper.selectPage} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
八月 01, 2018 1:19:19 下午 org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.0.2.Final
2018-08-01 13:19:25.315:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,[file:/G:/work/project/praiseme/code/praiseme-web/src/main/webapp/]}

重点 : No log4j2 configuration file found. Using default configuration:

没有找到配置文件log4j2.xml  ,所以使用 默认的配置,只打印出error级别的错误日志

看下web.xml 的配置 

 	<!--  1.1Spring 服务层的配置文件 -->
	<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/spring.xml</param-value>
	</context-param>
	
	<!--  Log4j2的配置文件 -->
	<context-param>
	    <param-name>log4jConfiguration</param-name>
	    <param-value>classpath:properties/log4j2.xml</param-value>
	</context-param>

检查项目的路径 : 发现是有这个文件的

然后尝试将classpath:  改为 classpath*:  ,也读取不到这个文件,

然后想是不是这个启动时读取的不是这个classpath下的文件,

因为启动时读取的spring配置文件是成功的,然后尝试将classpath下的目录的文件夹名称给改了,发现就报错了,

现在明确是读取这个路径下的配置文件了,

最后想是不是路径有问题,尝试将这个log4j2.xml文件直接放在classpath ,  即截图中的classes 目录下,发现正常读取。。。

请教一下,为什么在配置文件web.xml都不修改的情况下,挪一下log4j2.xml 的位置就可以呢,

web.xml 中明明写的是properties/log4j2.xml 啊

看了半天也没发现是什么问题导致。。。

 

 

 

 

 

 

展开
收起
爱吃鱼的程序员 2020-06-06 16:17:53 926 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>classpath*:properties/log4j2.xml</p>
    
                    
    
                            这个我试过了,不行。。。
    
    2020-06-06 16:18:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PostgresChina2018_赖思超_PostgreSQL10_hash索引的WAL日志修改版final 立即下载
Kubernetes下日志实时采集、存储与计算实践 立即下载
日志数据采集与分析对接 立即下载