Fix getting the right logger context.
@@ -337,7 +337,7 @@ public final class Configurator {
* @return the given logger
*/
public static Logger setLevel(final Logger logger, final Level level) {
- setLevel(logger.getName(), level);
+ setLevel(LoggerContext.getContext(StackLocatorUtil.getCallerClassLoader(2), false, null), logger.getName(), level);
return logger;
}
@@ -349,6 +349,14 @@ public final class Configurator {
return set;
}
+ private static void setLevel(final LoggerContext loggerContext, final String loggerName, final Level level) {
+ if (Strings.isEmpty(loggerName)) {
+ setRootLevel(level, loggerContext);
+ } else if (setLevel(loggerName, level, loggerContext.getConfiguration())) {
+ loggerContext.updateLoggers();
+ }
+ }
+
/**
* Sets logger levels.
*
@@ -379,12 +387,7 @@ public final class Configurator {
* the new level
*/
public static void setLevel(final String loggerName, final Level level) {
- final LoggerContext loggerContext = LoggerContext.getContext(StackLocatorUtil.getCallerClassLoader(2), false, null);
- if (Strings.isEmpty(loggerName)) {
- setRootLevel(level, loggerContext);
- } else if (setLevel(loggerName, level, loggerContext.getConfiguration())) {
- loggerContext.updateLoggers();
- }
+ setLevel(LoggerContext.getContext(StackLocatorUtil.getCallerClassLoader(2), false, null), loggerName, level);
}
/**
@@ -396,7 +399,7 @@ public final class Configurator {
* the new level
*/
public static void setLevel(final String loggerName, final String level) {
- setLevel(loggerName, Level.toLevel(level));
+ setLevel(LoggerContext.getContext(StackLocatorUtil.getCallerClassLoader(2), false, null), loggerName, Level.toLevel(level));
}
private static boolean setLevel(final String loggerName, final Level level, final Configuration config) {
