log4j.properties的放置位置

来源:百度文库 编辑:神马文学网 时间:2024/05/01 03:01:12
http://gigi-112.javaeye.com/blog/587965      今天和项目经理讨论了下log4j.properties具体的放置位置,我开始赞成直接放置在classpath下面,这样方便管理,对性能应该也有所提高,但经理从服务器管理者的角度告诉我这种做法的缺陷:更新log4j.properties时必然要重启应用,灵活性会降低。比如我要将输出控制由INFO 到 DEBUG 如果能配置到外面则方便很多。他还说了如果要重启某个应用需要重启多个服务器,因为做了集群,但我认为这个是危言耸听,做集群能没有同步么。

      总结:

1.log4j.properties放置在classpath下面。

优点:方便管理,节省资源。

缺点:灵活性差。

2.log4j.properties放置在外部。

有点:灵活性高。

缺点:需要建立相关的文档、相对浪费资源。

 

如何配置在外面:

Java代码
  1. public  Logger m_log = null;   
  2.        
  3. public ETrafficPlanService(){   
  4.     PropertyConfigurator.configure("data//config//log4j//log4j_etraffic.properties");   
  5.     m_log = Logger.getLogger(ETrafficPlanService.class);   
  6.     m_log.debug("debug test...........");   
  7. }  
 (#)