您的位置:首页 > 其它

日志框架实现实时修改,实时生效,具体框架思路(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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: