日志框架实现实时修改,实时生效,具体框架思路(7)
2015-06-29 16:57
246 查看
在第一章中有提到编写一个监听器,实现定时刷新log4j.propertes文件,实现修改之后日志文件生效。
该listener必须在Spring的listener后面启动,否则无法启动。
具体的web.xml配置 如下:
<listener>
<listener-class>com.work.log.listener.LogStartListener</listener-class>
</listener>
监听类的具体实现如下:
package com.work.log.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.PropertyConfigurator;
/**
* 日志启动Listener 该listener必须在Spring的listener后面启动,否则无法启动
* @version
* @see
* @since
*/
public class LogStartListener implements ServletContextListener
{
private static final int LOG4J_SCAN_TIME = 10;
/**
* 系统停止
* @param event ServletContextEvent
*/
public void contextDestroyed(ServletContextEvent event)
{
}
/**
* 系统启动
* @param event ServletContextEvent
*/
public void contextInitialized(ServletContextEvent event)
{
// 启动Log4j配置文件监听
configureAndWatch();
// 启动数据库日志
}
/**
* 设置Log4j定时读取配置文件
* @see [类、类#方法、类#成员]
*/
private void configureAndWatch()
{
// 定时扫描
PropertyConfigurator.configureAndWatch("log4j.propertes", LOG4J_SCAN_TIME);
}
}
该listener必须在Spring的listener后面启动,否则无法启动。
具体的web.xml配置 如下:
<listener>
<listener-class>com.work.log.listener.LogStartListener</listener-class>
</listener>
监听类的具体实现如下:
package com.work.log.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.PropertyConfigurator;
/**
* 日志启动Listener 该listener必须在Spring的listener后面启动,否则无法启动
* @version
* @see
* @since
*/
public class LogStartListener implements ServletContextListener
{
private static final int LOG4J_SCAN_TIME = 10;
/**
* 系统停止
* @param event ServletContextEvent
*/
public void contextDestroyed(ServletContextEvent event)
{
}
/**
* 系统启动
* @param event ServletContextEvent
*/
public void contextInitialized(ServletContextEvent event)
{
// 启动Log4j配置文件监听
configureAndWatch();
// 启动数据库日志
}
/**
* 设置Log4j定时读取配置文件
* @see [类、类#方法、类#成员]
*/
private void configureAndWatch()
{
// 定时扫描
PropertyConfigurator.configureAndWatch("log4j.propertes", LOG4J_SCAN_TIME);
}
}
相关文章推荐
- css3实现web app翻页过度效果
- NN(BP)算法
- C/C++求职宝典21个重点笔记(常考笔试面试点)
- 手机 Fildder真机抓包
- passing the word
- php基础教程-必备基础知识
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
- Interview Q&A - Java中sleep()和wait()有什么区别
- JAVA之关于This的用法
- [转]剑指offer面试题总结
- NDK 10分钟入门教程
- MySQL表空间的碎片整理
- poj 2777
- hdu 3394 railway 点连通分量判环
- C#高级编程三十二天----数组基础
- GDAL 生成shp文件
- Android Studio生成apk
- MAC系统IntelliJ Idea 14 常用快捷键汇总
- 剥下“java.lang.OutOfMemoryError: unable to create new native thread”的外衣
- mAdapter.notifyDataSetChanged()无法更新UI