[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-dev
Subject:    DO NOT REPLY [Bug 52168] New: change log4j property file at runtime
From:       bugzilla () apache ! org
Date:       2011-11-10 20:16:13
Message-ID: bug-52168-31091 () https ! issues ! apache ! org/bugzilla/
[Download RAW message or body]

https://issues.apache.org/bugzilla/show_bug.cgi?id=52168

             Bug #: 52168
           Summary: change log4j property file at runtime cause an empty
                    default log file is created
           Product: Log4j
           Version: 1.2
          Platform: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: alessio.pollero@gmail.com
    Classification: Unclassified


I have an application that uses log4j to log on a text file, i have placed a
log4j.properties file inside my executable jar file containing the default log
configuration parameters.

My log4j.properties file looks like the following :

log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=mylogfile.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{dd/MM/yyyy HH\:mm\:ss,SSS} %-5p
[%t] - %m%n

My application have also a command line option that allow the user to change
the log file name, so i have a function like the following that change the
settings of log4j at runtime :

public void changeLogFileName(String filename) {    
         
props.setProperty("log4j.appender.A1","org.apache.log4j.DailyRollingFileAppender");
          props.setProperty("log4j.appender.A1.DatePattern","'-'ddMMyyyy");
          props.setProperty("log4j.appender.A1.File",filename);
          LogManager.resetConfiguration();
          PropertyConfigurator.configure(props);
    }

Everything work fine, unless when the statement LogManager.resetConfiguration()
and/or PropertyConfigurator.configure(props) are executed a a default empty log
file (mylogfile.log) is automatically created. After that everything i log from
my application will be written correctly in the new file, but an empty file is
created anyway (with the name of the default log filename in the
log4j.properties).

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic