[ https://issues.apache.org/jira/browse/LOG4J2-945?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14534145#comment-14534145 ]
Stefan Wehner commented on LOG4J2-945: -------------------------------------- BTW: I was wondering why the StatusLogger is different from other loggers, and doesn't follow the Loggers + Appenders schema, but instead uses either an internal logger, or if a listeners are defined it uses the listeners... Anyways: if a regular logger with appenders setup has levels for each element, why is the StatusLogger's listenerLevel automatically calculated? We could simply add a public setter for the listenersLevel, and when the ConsoleListener is reconfigured from StatusConfiguration also reconfigure the StatusLogger's level. I think people take it for granted that you have different levels for loggers and appenders and you need to set both accordingly for messages to make it through. So maybe it'd also make sense to expose this level publicly and simply do something like this? {code} diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java index 745f411..799e59f 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java @@ -100,10 +100,6 @@ public final class StatusLogger extends AbstractLogger { listenersLock.writeLock().lock(); try { listeners.add(listener); - final Level lvl = listener.getStatusLevel(); - if (listenersLevel < lvl.intLevel()) { - listenersLevel = lvl.intLevel(); - } } finally { listenersLock.writeLock().unlock(); } @@ -118,14 +114,6 @@ public final class StatusLogger extends AbstractLogger { listenersLock.writeLock().lock(); try { listeners.remove(listener); - int lowest = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel(); - for (final StatusListener statusListener : listeners) { - final int level = statusListener.getStatusLevel().intLevel(); - if (lowest < level) { - lowest = level; - } - } - listenersLevel = lowest; } finally { listenersLock.writeLock().unlock(); } @@ -299,4 +287,8 @@ public final class StatusLogger extends AbstractLogger { return super.add(object); } } + + public void setListenersLevel(Level status) { + this.listenersLevel = status.intLevel(); + } } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java index 4d2ee51..30f002e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java @@ -194,6 +194,7 @@ public class StatusConfiguration { boolean configured = false; for (final StatusListener statusListener : this.logger.getListeners()) { if (statusListener instanceof StatusConsoleListener) { + this.logger.setListenersLevel(this.status); final StatusConsoleListener listener = (StatusConsoleListener) statusListener; listener.setLevel(this.status); if (this.verbosity == Verbosity.QUIET) { {code} > Reconfiguring statusLogger to a higher level doesn't work correctly > ------------------------------------------------------------------- > > Key: LOG4J2-945 > URL: https://issues.apache.org/jira/browse/LOG4J2-945 > Project: Log4j 2 > Issue Type: Bug > Components: Core > Affects Versions: 2.1 > Reporter: Stefan Wehner > Priority: Minor > Attachments: StatusLoggerBenchmark.java, callback_on_reconfig.patch, > log4j2-status-perf.xml, remove_listeners_level.patch > > > When reconfiguring log4j and changing the level of the status logger to a > higher level - e.g. from WARN to DEBUG, it doesn't work correctly. > Steps to reproduce: > # Configure from log4j2.xml containing: > {code} > <Configuration status="WARN" monitorInterval="5"> > ... > {code} > # With the app running, change status to a higher level: > {code} > <Configuration status="DEBUG" monitorInterval="5"> > ... > {code} > # Observe that the log config is reloaded, but no debug messages for the > status logger appear. > From what I've seen this is because the {{StatusConfiguration.initialize()}} > reconfigures the listeners' level > [StatusConfig:193|https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java;h=4d2ee51b4cf5dcb6f62029fe307093a759bf0af7;hb=HEAD#l193] > But it doesn't update the {{listenersLevel}} field that the {{StatusLogger}} > uses for checking if the logger is enabled (I understand this should be the > maximum of all of the listener's levels) > [StatusLogger:273|https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java;h=39d447d9793ca08a7d86b9eaaf6ef3dd406cf9a2;hb=HEAD#l273] > So in this case the listenersLevel is still at WARN, even though the console > listener has a DEBUG level, and all the log messages are ignored because > isEnabled(DEBUG) returns false. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org