Doubly called PropertyConfigurator differs from log4j
Logging Framework for C++
Brought to you by:
wilx
When I called PropertyConfigurator.configure()
twice with the same properties file, all the appenders are also doubled. So that all log messages are doubled!
I tested the same thing with log4j with below code, and it gave me only one log entry.
import java.util.*; import org.apache.log4j.*; public class DoubleConfigure { public static void main(String[] args) throws Exception { Properties properties = new Properties(); properties.put("log4j.rootLogger", "ALL, R"); properties.put("log4j.appender.R", "org.apache.log4j.ConsoleAppender"); properties.put("log4j.appender.R.layout", "org.apache.log4j.PatternLayout"); properties.put("log4j.appender.R.layout.ConversionPattern", "%d [%t] %-5p %c{1} - %m%n"); PropertyConfigurator.configure(properties); PropertyConfigurator.configure(properties); Logger logger = Logger.getLogger("Logger"); logger.debug("TEST!"); } }
Logged In: YES
user_id=989860
This is an important one, as it prevents you from properly re-configuring
a system. You can't remove appenders from a logger via the config files.
That's not good. I'm going to need to fix this myself for our product. I'll
submit my suggested changes when I do - Unless someone's already
working on it. Anyone... Anyone...
Logged In: YES
user_id=989860
This is an important one, as it prevents you from properly re-configuring
a system. You can't remove appenders from a logger via the config files.
That's not good. I'm going to need to fix this myself for our product. I'll
submit my suggested changes when I do - Unless someone's already
working on it. Anyone... Anyone...
Have you fixed it in your product? If you have, could you share the fix?
I have looked into the code and it seems that adding call to removeAllAppenders() right before the loop that calls addAppend() in PropertyConfigurator::configureLogger() is the right fix.
I have committed the suggested fix in revision 660 on the PRODUCTIN_1_0_x branch. It will be part of the next release candidate.
Diff: