Use system properties OR variables in log4j

后端 未结 5 1549
-上瘾入骨i
-上瘾入骨i 2021-02-05 13:00

I want to to do like this:


        

        
5条回答
  •  清酒与你
    2021-02-05 13:42

    You can do it by configure appender pragmatically

      FileAppender fa = new FileAppender();
      fa.setFile("/test/crm/log/error.log");
      fa.setLayout(new 
       PatternLayout("%C{1} %L [%t] %d{dd MMM,yyyy HH:mm:ss.SSS} %-5p - %m%n"));
      fa.setThreshold(Level.ERROR);
      fa.setAppend(true);
      fa.activateOptions();
      Logger.getRootLogger().addAppender(fa);
      // similarly you can add all appenders.
    
     // or just append file name alone 
     Logger log = Logger.getLogger(YourClass.class);
     FileAppender appender = (FileAppender) log.getAppender("ErrorLog");
     appender.setFile("appender");
    

提交回复
热议问题