I use log4j in my project and wanted to use FallbackErrorHandler for Backup-Reasons. So, when I want to implement a FallbackErrorHandler, you have to use the DOMConfigurator and that for a XML-Configurationfile.
But now, my customer doesn´t really like XML and looking for a way, he can configure the Logging-behaviour himself, I got the idea to load the basic configuration with the help of java-properties und instantiating the higher Appender or ErrorHandler with Java-Code, which I could configure with parameters.
The configuration of the ErrorHandler worked so far, the log4j-debug showing everythings correct, but I ran into a problem I could not solve until yet. My FallbackErrorHandler starts logging to the backupAppender already at the start of the programm, not when a standard appender failed. I couldn´t figure out what I´ve done wrong, I can post the code of the properties and the java-code if somebody wants to look at it, but at first, I wanted to ask, whether somebody ran into the same problem or has any experiences with configuring log4j within Java?
After weeks of trying I now finally found a solution. The key event was the discovery, that also the PropertyConfigurator has a class for ErrorHandler, although Geki wrote, that there is no possibility to configure a ErrorHandler with the PropertyConfigurator. So I went on trying.
Now I could simply combine the basic declaration in the log4j.properties with the linking of Logger, Appender and ErrorHandler in JavaCode.
So following stands in my Properties:
While com.foo.server is a part of my package hierarchy, com.foo.error is only a placeholder, so I can call it within Java-Code. That will look like this.
A known problem, the fallbackErrorHandler doesn´t reset when the Appender is on again, could be solved by restarting the configure()-method in or after situations, where normally the normal Appender can´t log.
Hope it could help somebody 🙂