@@ -317,38 +317,14 @@ public static LevelsContainer adjustLogLevels(String methodName, List<Class<?>>
317317 Map <Class <?>, Level > classLevels = new HashMap <>();
318318 for (Class <?> cls : classes ) {
319319 String className = cls .getName ();
320- LoggerConfig loggerConfig = config .getLoggerConfig (className );
321- LoggerConfig specificConfig = loggerConfig ;
322-
323- // We need a specific configuration for this logger,
324- // otherwise we would change the level of all other loggers
325- // having the original configuration as parent as well
326-
327- if (!loggerConfig .getName ().equals (className )) {
328- specificConfig = new LoggerConfig (className , loggerConfig .getLevel (), true );
329- specificConfig .setParent (loggerConfig );
330- config .addLogger (className , specificConfig );
331- }
332-
320+ LoggerConfig specificConfig = addLoggerConfigForCategory (config , className );
333321 classLevels .put (cls , specificConfig .getLevel ());
334322 specificConfig .setLevel (level );
335323 }
336324
337325 Map <String , Level > categoryLevels = new HashMap <>();
338326 for (String category : categories ) {
339- LoggerConfig loggerConfig = config .getLoggerConfig (category );
340- LoggerConfig specificConfig = loggerConfig ;
341-
342- // We need a specific configuration for this logger,
343- // otherwise we would change the level of all other loggers
344- // having the original configuration as parent as well
345-
346- if (!loggerConfig .getName ().equals (category )) {
347- specificConfig = new LoggerConfig (category , loggerConfig .getLevel (), true );
348- specificConfig .setParent (loggerConfig );
349- config .addLogger (category , specificConfig );
350- }
351-
327+ LoggerConfig specificConfig = addLoggerConfigForCategory (config , category );
352328 categoryLevels .put (category , specificConfig .getLevel ());
353329 specificConfig .setLevel (level );
354330 }
@@ -363,6 +339,22 @@ public static LevelsContainer adjustLogLevels(String methodName, List<Class<?>>
363339 return new LevelsContainer (classLevels , categoryLevels );
364340 }
365341
342+ private static LoggerConfig addLoggerConfigForCategory (Configuration config , String category ) {
343+ LoggerConfig loggerConfig = config .getLoggerConfig (category );
344+ LoggerConfig specificConfig = loggerConfig ;
345+
346+ // We need a specific configuration for this logger,
347+ // otherwise we would change the level of all other loggers
348+ // having the original configuration as parent as well
349+
350+ if (!loggerConfig .getName ().equals (category )) {
351+ specificConfig = new LoggerConfig (category , loggerConfig .getLevel (), true );
352+ specificConfig .setParent (loggerConfig );
353+ config .addLogger (category , specificConfig );
354+ }
355+ return specificConfig ;
356+ }
357+
366358 public static void revertLogLevels (String methodName , LevelsContainer container ) {
367359 LOGGER .warn ("++++++++++++++++++++++++++++ "
368360 + "Restoring log level setting for: " + container .classLevels .keySet ()
@@ -372,24 +364,24 @@ public static void revertLogLevels(String methodName, LevelsContainer container)
372364 LoggerContext ctx = (LoggerContext ) LogManager .getContext (false );
373365 Configuration config = ctx .getConfiguration ();
374366
375- container .classLevels .entrySet (). forEach (entry -> {
376- LoggerConfig loggerConfig = config .getLoggerConfig (entry . getKey () .getName ());
377- loggerConfig .setLevel (entry . getValue () );
367+ container .classLevels .forEach (( key , value ) -> {
368+ LoggerConfig loggerConfig = config .getLoggerConfig (key .getName ());
369+ loggerConfig .setLevel (value );
378370 });
379371
380- container .categoryLevels .entrySet (). forEach (entry -> {
381- LoggerConfig loggerConfig = config .getLoggerConfig (entry . getKey () );
382- loggerConfig .setLevel (entry . getValue () );
372+ container .categoryLevels .forEach (( key , value ) -> {
373+ LoggerConfig loggerConfig = config .getLoggerConfig (key );
374+ loggerConfig .setLevel (value );
383375 });
384376
385377 ctx .updateLoggers ();
386378 }
387379
388380 public static class LevelsContainer {
389381
390- final Map <Class <?>, Level > classLevels ;
382+ private final Map <Class <?>, Level > classLevels ;
391383
392- final Map <String , Level > categoryLevels ;
384+ private final Map <String , Level > categoryLevels ;
393385
394386 public LevelsContainer (Map <Class <?>, Level > classLevels , Map <String , Level > categoryLevels ) {
395387 this .classLevels = classLevels ;
0 commit comments