1日志级别热修改
web.xml
===============================================================================
org.springframework.web.util.Log4jConfigListener
log4jRefreshInterval
5000
===============================================================================
Spring的Log4jConfiglistener类会调用Log4j的PropertyConfigurator.configureAndWatch(),将刷新间隔作为参数传入。
public static void initLogging(String location, long refreshInterval) throws FileNotFoundException {
String resolvedLocation =SystemPropertyUtils.resolvePlaceholders(location);
File file = ResourceUtils.getFile(resolvedLocation);
if (!file.exists()) {
throw new FileNotFoundException("Log4j config file [" +resolvedLocation + "] not found");
}
if(resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
DOMConfigurator.configureAndWatch(file.getAbsolutePath(),refreshInterval);
}
else {
PropertyConfigurator.configureAndWatch(file.getAbsolutePath(),refreshInterval);
}
}
2日志文件编码格式
3日志文件保留时间
通过下面配置,可以限制DailyRollingFileAppender保留的文件个数。