zoukankan      html  css  js  c++  java
  • 利用【监听器】动态加载Log4j配置文件

    转自:https://veromca273.iteye.com/blog/1889304

    1 创建监听器:

    Java代码  收藏代码
    1. public class LogListener implements ServletContextListener  
    2. {  
    3.     private Log log = LogFactoryImpl.getFactory().getLog(LogListener.class);  
    4.     @Override  
    5.     public void contextDestroyed(ServletContextEvent arg0)  
    6.     {  
    7.         if (log.isDebugEnable())  
    8.         {  
    9.             log.debug("销毁LogListener....");  
    10.         }  
    11.     }  
    12.   
    13.     @Override  
    14.     public void contextInitialized(ServletContextEvent arg0)  
    15.     {     
    16.         // 配置log4j  
    17.         String filePath = "src/conf/log4j.xml";  
    18.         DOMConfigurator.configure(filePath);  
    19.         if (log.isDebugEnable())  
    20.         {  
    21.             log.debug("初始化Web日志成功....");  
    22.         }  
    23.     }  



    2 修改web.xml 注册监听器

    Java代码  收藏代码
      1. <listener>  
      2.     <listener-class>com.log.LogListener</listener-class>  
      3. </listener>     
  • 相关阅读:
    Lintcode: Wood Cut
    Lintcode: Update Bits
    Lintcode: Route Between Two Nodes in Graph
    Lintcode: Flip Bits
    Leetcode: Maximum Size Subarray Sum Equals k
    Lintcode: Subarray Sum Closest
    Lintcode: Remove Node in Binary Search Tree
    Lintcode: Majority Number III
    Leetcode: Range Sum Query
    Leetcode: Create Maximum Number
  • 原文地址:https://www.cnblogs.com/sharpest/p/7639452.html
Copyright © 2011-2022 走看看