Log4j路径配置:绝对路径、使用Listener、spring集成(配置web.xml)。
- 方法一
直接在log4j配置中写绝对路径
- 方法二
新建一个ServletContextListener的实现类Log4jConfigListener,Log4jConfigListener做:
String path = Environment.class.getResource("").getPath();
String webAppPath = path.substring(0, path.toUpperCase().lastIndexOf("WEB-INF/")).replaceAll("%20", " ");
System.setProperty("webapp",webAppPath + "logs/log.log");
在log4j配置中:
log4j.appender.A2.File=${webapp}/logs/log.log
也可以使用jvm里自带的参数例如user.home
- 方法三
(跟Spring集成):在web.xml中配置
|
|
然后在log4j中用上述配置的webAppRootKey对应的值
近期评论