vy commented on code in PR #2249: URL: https://github.com/apache/logging-log4j2/pull/2249#discussion_r1470220453
########## log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java: ########## @@ -92,6 +80,50 @@ private static MBeanNotificationInfo createNotificationInfo() { return new MBeanNotificationInfo(notifTypes, name, description); } + /// BEGIN: Conditional `StatusListener` registration /////////////////////////////////////////////////////////////// + + // `StatusLogger` contains a _fallback listener_ that defaults to a `StatusConsoleListener`. + // It is used to propagate logs when no listeners are available. + // If JMX registers itself always, unconditionally, this would render the fallback (console) listener ineffective. + // That is, no status logs would be written to console when `StatusLoggerAdmin` is in the classpath. + // To avoid this undesired behaviour, we register JMX status listener only when there is a party interested in these + // notifications. + + @Override + public void addNotificationListener( + final NotificationListener listener, final NotificationFilter filter, final Object handback) { + super.addNotificationListener(listener, filter, handback); + registeredNotificationListeners.add(listener); + updateStatusListenerRegistration(); + } + + @Override + public void removeNotificationListener(final NotificationListener listener) throws ListenerNotFoundException { + super.removeNotificationListener(listener); + registeredNotificationListeners.remove(listener); + updateStatusListenerRegistration(); Review Comment: @ppkarwasz, thanks for the due diligence during review. I implemented the `postDeregister()` approach in 88eb8fcb415bbe7abf544467d632cde12675d375. Would you mind checking it out, please? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org