[logback-user] runtime configuration
mateusz jedruch
mateusz.jedruch at gmail.com
Thu Dec 4 15:23:23 CET 2008
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>
More information about the Logback-user
mailing list