Log4j日志文件常用配置
2013-02-15 22:19
483 查看
1日志级别热修改
web.xml===============================================================================
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>5000</param-value>
</context-param>
===============================================================================
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日志文件编码格式
<appender name="FILEOUT" class="org.apache.log4j.DailyRollingFileAppender"><param name="File" value="${vc.log.path}/cdai_ssh.log" />
<param name="Encoding" value="UTF-8" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[CDAI_SSH]%d{yyy-MM-dd HH:mm:ss}%-5p%m%n"
/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="DEBUG" />
</filter>
</appender>
3日志文件保留时间
通过下面配置,可以限制DailyRollingFileAppender保留的文件个数。<param name="MaxBackupIndex"value="10"/>
相关文章推荐
- 软件开发工程师(JAVA)中级考试大纲-----四(四)Log4J的原理及配置;Log4J常用的API;在项目中应用日志框架Log4J关键类和接口介绍;Java properties配置文件log
- Log4j日志文件常用配置
- log4j常用配置以及日志文件保存位置
- log4j输出多个自定义日志文件,动态配置路径
- Log4j 日志工具demo以及配置文件实例
- log4j日志文件配置
- Log4J日志文件配置
- JBOSS jboss-log4j.xml文件中配置web工程日志
- Log4j的日志输出级别和配置文件详解
- Log4j中配置日志文件相对路径
- log4j日志的配置文件详解
- Log4j输出日志到文件[配置]
- Log4j按级别输出日志到不同文件配置分析
- log4j日志配置文件及将日志根据不同的等级输入到不同的文件之中
- log4j配置输出到多个日志文件
- Log4j中配置日志文件相对路径
- log4j输出多个自定义路径的日志文件,动态配置路径
- log4j配置文件及nutch中的日志配置 分类: B1_JAVA 2015-02-17 10:58 483人阅读 评论(0) 收藏
- Log4j 日志工具demo以及配置文件实例
- [转]tomcat6.0下的log4j日志文件配置过程