How to give dynamic file name in the appender in log4j.xml

后端 未结 5 1701
情深已故
情深已故 2020-11-28 06:16

I am using log4j to log information. I have used a log4j.xml file for creating log files. I have given the absolute path for each log file as a param

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 06:38

    In your class containing main method set the name of your class to some system property. In following example I used log_dir as property name.

    class ABC{
     public static void main(String s[]){
      System.setProperty("log_dir", ABC.class.getSimpleName());
     }
    }
    

    And in your log4j.xml file use log_dir property in File param's value attribute

    
      
      
      
    
    

    Works like a charm

提交回复
热议问题