设为首页 加入收藏

TOP

Log4j日志文件常用配置
2014-11-24 08:07:59 来源: 作者: 【 】 浏览:0
Tags:Log4j 日志 文件 常用 配置

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保留的文件个数。




】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇应用Libvirt连接KVM虚拟化平台 下一篇jQuery EasyUI datagrid动态查询..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)