JobEntryUtils { public static void removeAppenderFrom( Appender appender, Map<String, Level> logLevelCache, String... logNames ) { for ( String logName : logNames ) { Logger logger = findLogger( logName ); logger.removeAppender( appender ); if ( logLevelCache.containsKey( logger.getName() ) ) { logger.setLevel( logLevelCache.get( logger.getName() ) ); logLevelCache.remove( logger.getName() ); } } appender.close(); }  static Logger findLogger( String logName ); static void attachAppenderTo( Appender appender, LogLevel logLevel, Map<String, Level> logLevelCache,
      String... logNames ); static void removeAppenderFrom( Appender appender, Map<String, Level> logLevelCache, String... logNames ); static boolean asBoolean( String s, VariableSpace variableSpace ); static Long asLong( String s, VariableSpace variableSpace );  }
@Test public void removeAppenderFrom() { Map<String, Level> logLevelCache = new HashMap<String, Level>(); String loggerName = "testLogger"; logLevelCache.put( loggerName, Level.ERROR ); Log log = LogFactory.getLog( loggerName ); assertTrue( log instanceof Log4JLogger ); Log4JLogger log4jLogger = (Log4JLogger) log; Logger logger = log4jLogger.getLogger(); logger.setLevel( Level.INFO ); assertNotNull( logger ); assertFalse( logger.getAllAppenders().hasMoreElements() ); logger.addAppender( MOCK_APPENDER ); assertTrue( logger.getAllAppenders().hasMoreElements() ); try { JobEntryUtils.removeAppenderFrom( MOCK_APPENDER, logLevelCache, loggerName ); assertFalse( logger.getAllAppenders().hasMoreElements() ); assertEquals( Level.ERROR, logger.getLevel() ); assertEquals( 0, logLevelCache.size() ); } finally { logger.removeAllAppenders(); } }