I have a logging problem with log4j. I am using the configureAndWatch to make log4j poll the following config occasionnaly and update what logging is done:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Write logs to a file -->
<appender name="DEBUGGING" class="org.apache.log4j.RollingFileAppender">
...
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
...
</appender>
...
<category name="com.ourinternalpackage" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
</category>
<root>
<level value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>
This works well. Everything I expect ends up getting logged to console. Now I add (before the root element):
<category name="com.ourinternalpackage.somesubpackage.SomeClass" additivity="true">
<priority value="DEBUG"/>
<appender-ref ref="DEBUGGING"/>
</category>
Now, as expected, the log messages from SomeClass ends up in both the DEBUGGING log file and is logged to console. Great! However, when I change the priority of the category named "com.ourinternalpackage.somesubpackage.SomeClass" to OFF the logging to CONSOLE is also disabled. This is unexpected since the category named "com.ourinternalpackage" still has it's priority set to DEBUG and is logging to console. Other debug level messages, from classes in the com.ourinternalpackage, do end up in the console log. Additionally, if I remove the category with the appender-ref to DEBUGGING from the config file it keeps appending debug messages to the log.
Any ideas how to be able to toggle the logging on AND off for a specific category/logger without having to restart the application? In most cases the priority level for the category with name "com.ourinternalpackage" would be set to INFO. In which case I could set the priority of the category named "com.ourinternalpackage.somesubpackage.SomeClass" to INFO to reduce the ammount of logging done, but I would still be logging to both files. Which is something I'd like to avoid if possible.