Log4j2 - Overriding log file programmatically

末鹿安然 提交于 2020-04-21 13:05:20

问题


We are currently upgrading log4j1 to log4j2, In our project we have log4j1 code that overriding the log file programatically by calling below 2 methods together

  1. setAppend(false);
  2. activateOptions();

What is equivalent option in log4j2?. Below is my sample code?

class TestAppender extends RollingFileAppender {
   public void m1(){
      setAppend(false); 
      activateOptions();
   }
}



  class Test{
    public void callm1(){
    TestAppender ta = new TestAppender();
    ta.m1();

    }

log4j.properties

# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE= com.test.**TestAppender**
log4j.appender.FILE.File=${log}/log.out

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

This code is perfectly working now and we need log4j2 configuration.

Could someone please provide log4j2 code for above m1 method

Thanks, Durga

来源:https://stackoverflow.com/questions/47332241/log4j2-overriding-log-file-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!