Java Code Examples for org.apache.log4j.spi.LoggerRepository#setThreshold()

The following examples show how to use org.apache.log4j.spi.LoggerRepository#setThreshold() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyConfigurator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    Read configuration options from <code>properties</code>.

    See {@link #doConfigure(String, LoggerRepository)} for the expected format.
 */
 public
 void doConfigure(Properties properties, LoggerRepository hierarchy) {
   String value = properties.getProperty(LogLog.DEBUG_KEY);
   if(value == null) {
     value = properties.getProperty("log4j.configDebug");
     if(value != null)
LogLog.warn("[log4j.configDebug] is deprecated. Use [log4j.debug] instead.");
   }

   if(value != null) {
     LogLog.setInternalDebugging(OptionConverter.toBoolean(value, true));
   }

     //
     //   if log4j.reset=true then
     //        reset hierarchy
   String reset = properties.getProperty(RESET_KEY);
   if (reset != null && OptionConverter.toBoolean(reset, false)) {
         hierarchy.resetConfiguration();
   }

   String thresholdStr = OptionConverter.findAndSubst(THRESHOLD_PREFIX,
					       properties);
   if(thresholdStr != null) {
     hierarchy.setThreshold(OptionConverter.toLevel(thresholdStr,
					     (Level) Level.ALL));
     LogLog.debug("Hierarchy threshold set to ["+hierarchy.getThreshold()+"].");
   }

   configureRootCategory(properties, hierarchy);
   configureLoggerFactory(properties);
   parseCatsAndRenderers(properties, hierarchy);

   LogLog.debug("Finished configuring.");
   // We don't want to hold references to appenders preventing their
   // garbage collection.
   registry.clear();
 }
 
Example 2
Source File: HaxeDebugLogger.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public synchronized void mute(LoggerRepository hierarchy) throws IllegalStateException {
  if (null == hierarchy) {
    throw new IllegalArgumentException("Null Hierarchy is not allowed.");
  }
  if (null != capturedHierarchy && capturedHierarchy != hierarchy) {
    throw new IllegalStateException("Trying to mute a hierarchy that is not the one previously captured.");
  }
  captureState(hierarchy);
  hierarchy.setThreshold(Level.OFF);
}
 
Example 3
Source File: LoggerTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public
void testDisable1() {
  CountingAppender caRoot = new CountingAppender();
  Logger root = Logger.getRootLogger();    
  root.addAppender(caRoot);

  LoggerRepository h = LogManager.getLoggerRepository();
  //h.disableDebug();
  h.setThreshold((Level) Level.INFO);
  assertEquals(caRoot.counter, 0);     

  root.debug(MSG); assertEquals(caRoot.counter, 0);  
  root.info(MSG); assertEquals(caRoot.counter, 1);  
  root.log(Level.WARN, MSG); assertEquals(caRoot.counter, 2);  
  root.warn(MSG); assertEquals(caRoot.counter, 3);  

  //h.disableInfo();
  h.setThreshold((Level) Level.WARN);
  root.debug(MSG); assertEquals(caRoot.counter, 3);  
  root.info(MSG); assertEquals(caRoot.counter, 3);  
  root.log(Level.WARN, MSG); assertEquals(caRoot.counter, 4);  
  root.error(MSG); assertEquals(caRoot.counter, 5);  
  root.log(Level.ERROR, MSG); assertEquals(caRoot.counter, 6);  

  //h.disableAll();
  h.setThreshold(Level.OFF);
  root.debug(MSG); assertEquals(caRoot.counter, 6);  
  root.info(MSG); assertEquals(caRoot.counter, 6);  
  root.log(Level.WARN, MSG); assertEquals(caRoot.counter, 6);  
  root.error(MSG); assertEquals(caRoot.counter, 6);  
  root.log(Level.FATAL, MSG); assertEquals(caRoot.counter, 6);  
  root.log(Level.FATAL, MSG); assertEquals(caRoot.counter, 6);  

  //h.disable(Level.FATAL);
  h.setThreshold(Level.OFF);
  root.debug(MSG); assertEquals(caRoot.counter, 6);  
  root.info(MSG); assertEquals(caRoot.counter, 6);  
  root.log(Level.WARN, MSG); assertEquals(caRoot.counter, 6);  
  root.error(MSG); assertEquals(caRoot.counter, 6);
  root.log(Level.ERROR, MSG); assertEquals(caRoot.counter, 6);  
  root.log(Level.FATAL, MSG); assertEquals(caRoot.counter, 6);  
}