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
          主站蜘蛛池模板: 六枝特区| 旬邑县| 云林县| 科尔| 揭阳市| 琼结县| 湘阴县| 桂平市| 儋州市| 钦州市| 项城市| 海安县| 穆棱市| 崇信县| 高密市| 盘山县| 芒康县| 新巴尔虎右旗| 石棉县| 镇宁| 乌拉特后旗| 邵阳县| 西乌| 富川| 北安市| 呼伦贝尔市| 芦溪县| 贵定县| 芒康县| 桂阳县| 凤山县| 石嘴山市| 新沂市| 宁都县| 绥化市| 邢台市| 富平县| 伊川县| 泰兴市| 馆陶县| 博罗县|