Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.classic.jul;
 
 
 import java.util.List;
 import java.util.Set;
Propagate level changes made to a logback logger into the equivalent logger in j.u.l.
 
 public class LevelChangePropagator extends ContextAwareBase implements LoggerContextListenerLifeCycle {
 
   private Set julLoggerSet = new HashSet();
   boolean isStarted = false;
   boolean resetJUL = false;
 
   public void setResetJUL(boolean resetJUL) {
     this. = resetJUL;
   }
   
   public boolean isResetResistant() {
     return false;
   }
 
   public void onStart(LoggerContext context) {
   }
 
   public void onReset(LoggerContext context) {
   }
 
   public void onStop(LoggerContext context) {
   }
 
   public void onLevelChange(Logger loggerLevel level) {
     propagate(loggerlevel);
   }
 
   private void propagate(Logger loggerLevel level) {
     addInfo("Propagating " + level + " level on " + logger + " onto the JUL framework");
     java.util.logging.Logger julLogger = JULHelper.asJULLogger(logger);
     // prevent garbage collection of jul loggers whose level we set
     // see also  http://jira.qos.ch/browse/LBCLASSIC-256
     .add(julLogger);
     java.util.logging.Level julLevel = JULHelper.asJULLevel(level);
     julLogger.setLevel(julLevel);
   }
 
   public void resetJULLevels() {
     LogManager lm = LogManager.getLogManager();
 
     Enumeration e = lm.getLoggerNames();
     while (e.hasMoreElements()) {
       String loggerName = (Stringe.nextElement();
       java.util.logging.Logger julLogger = lm.getLogger(loggerName);
       if (JULHelper.isRegularNonRootLogger(julLogger) && julLogger.getLevel() != null) {
         addInfo("Setting level of jul logger [" + loggerName + "] to null");
         julLogger.setLevel(null);
       }
     }
   }
 
   private void propagateExistingLoggerLevels() {
     LoggerContext loggerContext = (LoggerContext;
     List<LoggerloggerList = loggerContext.getLoggerList();
     for (Logger l : loggerList) {
       if (l.getLevel() != null) {
         propagate(ll.getLevel());
       }
     }
   }
 
   public void start() {
     if () {
       resetJULLevels();
     }
 
     = true;
  }
  public void stop() {
     = false;
  }
  public boolean isStarted() {
    return ;
  }
New to GrepCode? Check out our FAQ X