博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
log4j.properties路径修改后web.xml配置
阅读量:4350 次
发布时间:2019-06-07

本文共 1922 字,大约阅读时间需要 6 分钟。

org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
classpath:log4j.properties

此时,log4j.properties在根目录src下。


 log4j.properties文件

#the first parameter is the level of the log output#the second parameter is the location of the log outputlog4j.rootLogger=debug,stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.err#use simple layoutlog4j.appender.stdout.layout=org.apache.log4j.SimpleLayoutlog4j.appender.logfile=org.apache.log4j.FileAppenderlog4j.appender.logfile.File=d:/bjsxt.loglog4j.appender.logfile.layout=org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %F %p %m%n 

 


 

在web项目中:一般我们直接将log4j.properties放置在src目录下,这样系统自动会找到的,其实就是放在WEB-INF/classes文件下。这个路径在classpath下,所以直接就能找到。我们写Logger的时候如下

如果现在我们想把log4j.properties文件放置在其它目录下,例如:WEB-INF下和web.xml放在一起。这时候就需要我们手动指定log4j配置文件的路径,否则系统是找不到的。 一、首先我们在web.xml中配置好log4j.properties路径:       
log4jConfigLocation
/WEB-INF/log4j.properties
二、然后写个servlet,部分代码如下: public void init() { String prefix = getServletContext().getRealPath("/"); String file = getInitParameter("log4jConfigLocation"); if (file != null) { PropertyConfigurator.configure(prefix + file); }} 三、在web.xml中配置servlet,并将log4jConfigLocation加入到Servlet中,让其Server启动即运行:
your servlet
your servelt class
log4jConfigLocation
/WEB-INF/log4j.properties
1

  转载自:https://blog.csdn.net/u014756827/article/details/52488586

  附:logback的使用与详解:https://www.cnblogs.com/warking/p/5710303.html

  maven配置logback : https://www.cnblogs.com/quchunhui/p/5783172.html

转载于:https://www.cnblogs.com/deptop/p/9334744.html

你可能感兴趣的文章
【vim】实时加密文本 ggVGg?
查看>>
利用NLTK进行分词
查看>>
php 获取文件后缀最简单的方法
查看>>
微信小程序获取用户信息“授权失败”场景的处理
查看>>
selenium3.7版本无法new WebDriver Firefox()解决方法
查看>>
Java 坦克大战
查看>>
php服务器session突然不能用了
查看>>
第六周作业
查看>>
[SCOI2007]最大土地面积
查看>>
jQuery之克隆事件--clone()与clone(true)区别
查看>>
nodejs+express blog项目分享
查看>>
第十三周(动物这样叫)
查看>>
在Redhat Linux中执行非Redhat的Openstack, Redhat将对其Linux不提供支持
查看>>
LibreOJ #113. 最大异或和
查看>>
修改日历控件的默认样式
查看>>
Linux上部署Tomcat+Nginx负载均衡
查看>>
微信运动没有步数解决办法
查看>>
xBIM 基础14 使用LINQ实现最佳性能(优化查询)
查看>>
在windows phone 中使用原生代码开发程序(native code)
查看>>
C和指针 学习笔记-4.函数
查看>>