0

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

Durga
  • 1
  • 3
  • I don't think you've provided enough information regarding how you were calling the log4j1 methods or about what you're trying to achieve. Also, this sounds like it could be an [XY Problem](https://meta.stackexchange.com/a/66378) - why are you trying to configure logging programmatically instead of using a configuration file? – D.B. Nov 16 '17 at 16:48
  • @D.B. If that's what you think, you should vote to close as "unclear what you're asking". However the question has now been modified to fill that info. – Olivier Grégoire Nov 17 '17 at 18:13
  • Sorry, I haven't provided much info. I modified the question with more details. Please look into it and see if you can help – Durga Nov 18 '17 at 03:13
  • @ D.B. @ olivier-grégoire , Did you get a chance to look into it. – Durga Nov 21 '17 at 10:08
  • You are overriding the rolling file appender to set append to false? Why can’t you just specify that in the configuration. If you do that then converting to Log4j 2 is trivial. – rgoers Nov 27 '17 at 07:30
  • Can you please explain **why** you need to do this per my original comment? – D.B. Nov 28 '17 at 23:10

0 Answers0