public static void logOnlyErrors() { Logger root = Logger.getRootLogger(); root.setLevel(Level.ERROR); Enumeration allLoggers = root.getLoggerRepository().getCurrentCategories(); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.ERROR); } }
LogLog.error("Root level cannot be inherited. Ignoring directive."); } else { logger.setLevel(null); logger.setLevel(OptionConverter.toLevel(priStr, Level.DEBUG)); } else { LogLog.debug("Desired Level sub-class: ["+className+']'); Level pri = (Level) toLevelMethod.invoke(null, new Object[] {priStr}); logger.setLevel(pri); } catch (Exception oops) { LogLog.error("Could not create level ["+priStr+
/** Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories to <code>null</code>, sets their additivity flag to <code>true</code> and sets the level of the root logger to {@link Level#DEBUG DEBUG}. Moreover, message disabling is set its default "off" value. <p>Existing categories are not removed. They are just reset. <p>This method should be used sparingly and with care as it will block all logging until it is completed.</p> @since 0.8.5 */ public void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); // the synchronization is needed to prevent JDK 1.2.x hashtable // surprises synchronized(ht) { shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null); } } rendererMap.clear(); }
public void setPriority(Priority priority) { setLevel((Level) priority); }
private void setRootLogLevel(Level l) { // This might stop working in log4j version 2. See // http://stackoverflow.com/questions/23434252/programmatically-change-log-level-in-log4j2 l4jlogger.getParent().setLevel(l); }
@Managed public void setLevel(final String levelString) { // Allow erasing the current level using the empty string. if (levelString == null || levelString.trim().isEmpty()) { logger.setLevel(null); } else { final LogLevel level = LogLevel.getLogLevel(levelString); if (level != null) { logger.setLevel(level.getLevel()); } } }
p = OptionConverter.toLevel(s, p); logger.setLevel(p);
p = OptionConverter.toLevel(s, p); logger.setLevel(p);
/** * initializes the log system using the logfile argument */ private void internalInit( String logfile ) throws Exception { /* * do it by our classname to avoid conflicting with anything else * that might be used... */ logger = Category.getInstance(this.getClass().getName()); logger.setAdditivity(false); /* * Priority is set for DEBUG becouse this implementation checks * log level. */ logger.setLevel(Level.DEBUG); appender = new RollingFileAppender( new PatternLayout( "%d - %m%n"), logfile, true); appender.setMaxBackupIndex( 1 ); appender.setMaximumFileSize( 100000 ); logger.addAppender(appender); }
/** * initializes the log system using the logfile argument */ private void internalInit( String logfile ) throws Exception { /* * do it by our classname to avoid conflicting with anything else * that might be used... */ logger = Category.getInstance(this.getClass().getName()); logger.setAdditivity(false); /* * Priority is set for DEBUG becouse this implementation checks * log level. */ logger.setLevel(Level.DEBUG); appender = new RollingFileAppender( new PatternLayout( "%d - %m%n"), logfile, true); appender.setMaxBackupIndex( 1 ); appender.setMaximumFileSize( 100000 ); logger.addAppender(appender); }
LogLog.error("Root level cannot be inherited. Ignoring directive."); } else { logger.setLevel(null); logger.setLevel(OptionConverter.toLevel(priStr, Level.DEBUG)); } else { LogLog.debug("Desired Level sub-class: ["+className+']'); Level pri = (Level) toLevelMethod.invoke(null, new Object[] {priStr}); logger.setLevel(pri); } catch (Exception oops) { LogLog.error("Could not create level ["+priStr+
/** * Removes the appender that may have been setup by {@link #interceptLogging(String)}. Also, * invokes {@link org.apache.hivemind.util.PropertyUtils#clearCache()}. */ protected void tearDown() throws Exception { super.tearDown(); if (_appender != null) { _appender = null; Logger logger = LogManager.getLogger(_interceptedLoggerName); logger.setLevel(null); logger.setAdditivity(true); logger.removeAllAppenders(); } PropertyUtils.clearCache(); ServiceSerializationHelper.setServiceSerializationSupport(null); }
@Override public void doConfigure( final URL notUsed, final LoggerRepository repo ) { final Layout layout = new PatternLayout( pattern ); final ConsoleAppender cAppender = new ConsoleAppender( layout ); cAppender.setThreshold( Level.ALL ); repo.setThreshold( level ); repo.getRootLogger() .removeAllAppenders(); repo.getRootLogger() .setLevel( level ); repo.getRootLogger() .addAppender( cAppender ); @SuppressWarnings( "unchecked" ) final List<Logger> loggers = Collections.list( repo.getCurrentLoggers() ); for ( final Logger logger : loggers ) { logger.setLevel( level ); } @SuppressWarnings( "unchecked" ) final List<Category> cats = Collections.list( repo.getCurrentCategories() ); for ( final Category cat : cats ) { cat.setLevel( level ); } } };
/** Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories to <code>null</code>, sets their additivity flag to <code>true</code> and sets the level of the root logger to {@link Level#DEBUG DEBUG}. Moreover, message disabling is set its default "off" value. <p>Existing categories are not removed. They are just reset. <p>This method should be used sparingly and with care as it will block all logging until it is completed.</p> @since 0.8.5 */ public void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); // the synchronization is needed to prevent JDK 1.2.x hashtable // surprises synchronized(ht) { shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null); } } rendererMap.clear(); }
/** Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories to <code>null</code>, sets their additivity flag to <code>true</code> and sets the level of the root logger to {@link Level#DEBUG DEBUG}. Moreover, message disabling is set its default "off" value. <p>Existing categories are not removed. They are just reset. <p>This method should be used sparingly and with care as it will block all logging until it is completed.</p> @since 0.8.5 */ public void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); // the synchronization is needed to prevent JDK 1.2.x hashtable // surprises synchronized(ht) { shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null); } } rendererMap.clear(); }
@Override public void doConfigure( final URL notUsed, final LoggerRepository repo ) { final ConsoleAppender cAppender = new ConsoleAppender( new SimpleLayout() ); cAppender.setThreshold( Level.ALL ); repo.setThreshold( level ); repo.getRootLogger().removeAllAppenders(); repo.getRootLogger().setLevel( level ); repo.getRootLogger().addAppender( cAppender ); @SuppressWarnings( "unchecked" ) List<Logger> loggers = Collections.list( repo.getCurrentLoggers() ); for ( final Logger logger : loggers ) { logger.setLevel( level ); } @SuppressWarnings( "unchecked" ) List<Category> cats = Collections.list( repo.getCurrentCategories() ); for ( final Category cat : cats ) { cat.setLevel( level ); } for ( Map.Entry<String, Level> customEntry : customLevels.entrySet() ) { String key = customEntry.getKey(); Logger logger = repo.getLogger( key ); logger.setLevel( customEntry.getValue() ); } } };
/** Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories to <code>null</code>, sets their additivity flag to <code>true</code> and sets the level of the root logger to {@link Level#DEBUG DEBUG}. Moreover, message disabling is set its default "off" value. <p>Existing categories are not removed. They are just reset. <p>This method should be used sparingly and with care as it will block all logging until it is completed.</p> @since 0.8.5 */ public void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); // the synchronization is needed to prevent JDK 1.2.x hashtable // surprises synchronized(ht) { shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null); } } rendererMap.clear(); }
/** * Sets up an appender to intercept logging for the specified logger. Captured log events can be * recovered via {@link #getInterceptedLogEvents()}. */ protected void interceptLogging(String loggerName) { Logger logger = LogManager.getLogger(loggerName); logger.removeAllAppenders(); _interceptedLoggerName = loggerName; _appender = new StoreAppender(); _appender.activateOptions(); logger.setLevel(Level.DEBUG); logger.setAdditivity(false); logger.addAppender(_appender); }