[英]Log4j Manual Configuration with Java Properties
我正在尝试在Spring Web应用程序中手动加载log4j.properties( mylog4j.properties )文件。 该文件位于/ WEB-INF /下 ,我正在SYPLogger类中读取此文件,如下所示:
private static final String CONF_FILE_NAME = "mylog4j.properties";
Properties props = new Properties();
props.load(new FileInputStream(CONF_FILE_NAME));
PropertyConfigurator.configure(props);
尽管我尝试了其他位置,但无法读取文件。 当我给出配置文件的完整路径时,一切正常。 但是上面的代码给出了FileNotFoundException(系统找不到指定的文件)。 请帮忙。 提前致谢。
尝试下一个:
String path = Thread.currentThread()
.getContextClassLoader()
.getResource("/")
.toURI()
.resolve("../mylog4j.properties")
.getPath();
Properties props = new Properties();
props.load(new FileInputStream(path));
PropertyConfigurator.configure(props);
换句话说,您是否看到过org.springframework.web.util.Log4jConfigListener
类。 您可以在web.xml
文件中配置此侦听器。 例如:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/mylog4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.