On Jul 12, 2006, at 12:20 PM, Sharma, Siddharth wrote:

Greetings

In log4j.xml, we have set the threshold to be 'INFO'.
We have written a servlet that takes the log level as a parameter and
dynamically changes log4j's log level.
This is to facilitate bumping the log level up on-demand when an exception
occurs to capture more information.

Here is the code:
LoggerRepository logRepository = LogManager.getLoggerRepository();
logRepository.setThreshold(someLogLevel);


But I find that the log4j does not get configured at runtime to log at a
level lower than what is defined in log4j.xml.
In other words, I can successfully change to WARN, ERROR or FATAL and then back down to INFO, but I cannot change it to DEBUG (since log4j.xml has
INFO).

I am hoping this is possible to do and will appreciate the code that will
achieve this.
I can certainly change log4j.xml to have a threshold of DEBUG and then
programmatically change it to INFO during server startup. But I'd rather not
do it that way since it is a HACK!

Thanks in advance
Sid



Your code is changing the hierarchy-wide threshold. It is likely that you configuration file is setting the logger thresholds. The level of a logging request must be the same or higher than both the hierarchy-wide threshold and appropriate logger threshold before a logging event is accepted.

The logger hierarchy threshold (what your code is change) is set in a XML configuration file like:

<log4j:configuration threshold="INFO">

While a logger threshold (which you aren't modifying in your code) if set like:

<root>
    <level value="INFO"/>
    ...
</root>

or

<logger name="org.example.foobar">
        <level value="INFO"/>
...
</logger>
        
What I would recommend is to change your configuration file so that the hierarchy-wide threshold is set to INFO and any logger-specific threshold is set to a lower level. Until your hierarchy-wide threshold changing code is executed, any request below the hierarchy- wide threshold is discarded regardless of the logger-specific thresholds. Only when the hierarchy-wide threshold is lowered, would the logger-specific thresholds come into play.

If you still have questions, please provide relevant parts of your log4j.xml file.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to