[logback-user] runtime configuration

mateusz jedruch mateusz.jedruch at gmail.com
Thu Dec 4 17:32:48 CET 2008


Ok, added
http://jira.qos.ch/browse/LBCLASSIC-90
cheers
-mateusz



On Thu, Dec 4, 2008 at 5:09 PM, Ceki Gulcu <ceki at qos.ch> wrote:
>
> This is a known bug which was recently corrected. See
> http://jira.qos.ch/browse/LBCLASSIC-83 for details.
>
> Setting logger levels to null is fairly easy to do. However, loggers cannot be
> removed due to consistency reasons. If you'd like loggers to be nulled during
> reset, then may I ask you to create a jira issue?
>
> mateusz jedruch wrote:
>> Actually I need two things:
>>
>> * set the level of logger to null
>> * reset the configuration of logger context to be the same as the one
>> when application started (before any runtime changes)
>>
>> BTW using the ch.qos.logback.classic.jmx.Configurator is possible to get
>> NPE:
>>
>>         Configurator config = new Configurator(lc);
>>         config.setLoggerLevel("foo.bar", "null");  //ok, level of
>> foo.bar is null
>>         config.setLoggerLevel("foo.bar", "info");  //ok, level of
>> foo.bar is INFO
>>         config.setLoggerLevel("foo.bar", "null"); //NPE
>>
>> Stack trace:
>> Exception in thread "main" java.lang.NullPointerException
>>       at ch.qos.logback.classic.Logger.setLevel(Logger.java:193)
>>       at ch.qos.logback.classic.jmx.Configurator.setLoggerLevel(Configurator.java:92)
>>         ...
>> -mateusz
>>
>> On Thu, Dec 4, 2008 at 4:23 PM, Ceki Gulcu <ceki at qos.ch> wrote:
>>> LoggerContext.reset (aka shutdownAndReset) does not touch logger levels. This is
>>>  a relic from log4j, which behaves in the same way. Would you like the level
>>> values nulled as well?
>>>
>>> mateusz jedruch wrote:
>>>> Hi,
>>>> I am preparing something like web interface for my app logging configuration,
>>>> similar to yours JMX configurator.
>>>> As I noticed when you add new logger in the runtime then it is impossible
>>>> to remove it (set its log level null). I have checked the shutdownAndReset()
>>>> and id doesn't work.
>>>>
>>>> I have attached the source code which should explain you what I would like
>>>> achieved. Could you check it?
>>>>
>>>> Thanks,
>>>> -mateusz
>>>>
>>>> package foo;
>>>>
>>>> import org.slf4j.Logger;
>>>> import org.slf4j.LoggerFactory;
>>>>
>>>> import ch.qos.logback.classic.Level;
>>>> import ch.qos.logback.classic.LoggerContext;
>>>> import ch.qos.logback.classic.jmx.Configurator;
>>>>
>>>> public class Main {
>>>>
>>>>     private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
>>>>
>>>>     public static void main(String[] args) {
>>>>         LOGGER.info("Message #1"); //shouldn't be logged, LOGGER's
>>>> level is null so takes root's off level
>>>>         LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
>>>>         ch.qos.logback.classic.Logger log = lc.getLogger(LOGGER.getName());
>>>>         log.setLevel(Level.INFO);
>>>>         LOGGER.info("Message #2"); //should be logged, LOGGER's level is info
>>>>         Configurator config = new Configurator(lc);
>>>>         config.reload(); //shutdownAndReset() is call inside this method
>>>>         LOGGER.info("Message #3"); // why it is logged here ? LOGGER's
>>>> level is still INFO, shouldn't be null ?
>>>>     }
>>>> }
>>>>
>>>> logback.xml:
>>>>
>>>> <configuration>
>>>> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>>>>     <layout class="ch.qos.logback.classic.PatternLayout">
>>>>         <Pattern>%d{HH:mm:ss.SSS} [%thread] %5level %logger{18} -
>>>> %msg%n</Pattern>
>>>>     </layout>
>>>> </appender>
>>>>
>>>> <root>
>>>>     <level value="off" />
>>>>     <appender-ref ref="STDOUT" />
>>>> </root>
>>>> </configuration>
>>>> _______________________________________________
>>>> Logback-user mailing list
>>>> Logback-user at qos.ch
>>>> http://qos.ch/mailman/listinfo/logback-user
>>>>
>>> --
>>> Ceki Gülcü
>>> Logback: The reliable, generic, fast and flexible logging framework for Java.
>>> http://logback.qos.ch
>>> _______________________________________________
>>> Logback-user mailing list
>>> Logback-user at qos.ch
>>> http://qos.ch/mailman/listinfo/logback-user
>>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
>>
>
> --
> Ceki Gülcü
> Logback: The reliable, generic, fast and flexible logging framework for Java.
> http://logback.qos.ch
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>


More information about the Logback-user mailing list