zhyiwww
          用平實的筆,記錄編程路上的點點滴滴………
          posts - 536,comments - 394,trackbacks - 0

          (1)讀出log4j文件到Properties對象
          ?? ?
          public Properties getLog4jProperties(){
          ?? ??? ?Properties p = new Properties();
          ?? ??? ?InputStream is = this.getClass().getClassLoader().getResourceAsStream("/log4j.properties");
          ?? ??? ?if(is==null){
          ?? ??? ??? ?log.warn("read log4j properties file error ");
          ?? ??? ??? ?return p;
          ?? ??? ?}
          ?? ??? ?try {
          ?? ??? ??? ?p.load(is);
          ?? ??? ?} catch (IOException e) {
          ?? ??? ??? ?e.printStackTrace();
          ?? ??? ?}
          ?? ??? ?return p;
          ?? ?}
          ?? ?

          (2)重新設置屬性

          ?? ??? ?Properties log4jCfg = getLog4jProperties();
          ?? ??? ?
          ?? ??? ?log.info("log4j config properties : "+log4jCfg);
          ?? ??? ?
          ?? ??? ?log4jCfg.setProperty("log4j.appender.TASKlog.File", logFile);
          ?? ??? ?
          ?? ??? ?log.info("log4j properties prpoperties is : " + log4jCfg);


          (3)配置生效?? ??? ?
          ?? ??? ?
          ?? ??? ?PropertyConfigurator.configure(log4jCfg);

          上面的屬性設置里面,我把原來的日志文件換成了一個新的日志文件。
          通過這種方法,就可以實現在任何時候切換到一個新的日志文件開始記錄。




          ?



          |----------------------------------------------------------------------------------------|
                                     版權聲明  版權所有 @zhyiwww
                      引用請注明來源 http://www.aygfsteel.com/zhyiwww   
          |----------------------------------------------------------------------------------------|
          posted on 2009-06-10 16:52 zhyiwww 閱讀(1130) 評論(0)  編輯  收藏 所屬分類: j2ee
          主站蜘蛛池模板: 县级市| 漳平市| 昭通市| 石狮市| 佳木斯市| 合作市| 勐海县| 朝阳市| 双牌县| 道真| 兰州市| 隆德县| 德令哈市| 镶黄旗| 深泽县| 昭觉县| 商水县| 康平县| 姚安县| 栖霞市| 岳普湖县| 江陵县| 精河县| 虞城县| 宁武县| 长乐市| 泽普县| 图们市| 额敏县| 定兴县| 景洪市| 卢龙县| 赞皇县| 库伦旗| 开鲁县| 镇坪县| 定西市| 潞西市| 夹江县| 荣成市| 桦川县|