标签:方式 property public resource context ati inter 技术 interval
满足以下条件时:
1).配置文件名为log4j.properties
2).在classpath根目录下(即resources根目录下)
spring会自动加载log4j.properties文件,无需显式加载.
使用spring提供的Log4jConfigListener,在web.xml中加载配置文件
<!-- 设置Log4j配置文件位置 --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:properties/log4j.properties</param-value> </context-param> <!-- 刷新Log4j配置文件变动的间隔,单位为毫秒 --> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>10000</param-value> </context-param> <!-- 监听器要写在下边 --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener>
public class TestLog4j {
public static void main(String[] args) {
PropertyConfigurator.configure( " D:/Code/conf/log4j.properties " );
Logger logger = Logger.getLogger(TestLog4j. class );
logger.debug( " debug " );
logger.error( " error " );
}
}
标签:方式 property public resource context ati inter 技术 interval
原文地址:https://www.cnblogs.com/jinyu59/p/10631959.html