mimaison commented on code in PR #17373: URL: https://github.com/apache/kafka/pull/17373#discussion_r1860858017
########## connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Loggers.java: ########## @@ -174,43 +178,46 @@ private synchronized List<org.apache.log4j.Logger> loggers(String namespace) { } // visible for testing - org.apache.log4j.Logger lookupLogger(String logger) { + org.apache.logging.log4j.Logger lookupLogger(String logger) { return LogManager.getLogger(logger); } - @SuppressWarnings("unchecked") - // visible for testing - Enumeration<org.apache.log4j.Logger> currentLoggers() { - return LogManager.getCurrentLoggers(); + List<org.apache.logging.log4j.Logger> currentLoggers() { + LoggerContext context = (LoggerContext) LogManager.getContext(false); + Collection<LoggerConfig> loggerConfigs = context.getConfiguration().getLoggers().values(); + return loggerConfigs.stream() + .map(LoggerConfig::getName) + .distinct() + .map(LogManager::getLogger) + .collect(Collectors.toUnmodifiableList()); Review Comment: With the current code, updating Connect loggers does not work. For example, I get: ``` $ curl -X PUT -H "Content-Type: application/json" -d '{"level": "DEBUG"}' \ localhost:8083/admin/loggers/root {"error_code":500,"message":null} ``` We should not return an UnmodifiableList here. In the `loggers()` method above we call `add()` on the `List`. Here is the stack trace: ``` [2024-11-27 16:17:39,224] INFO Setting level of namespace root and children to DEBUG (org.apache.kafka.connect.runtime.Loggers:131) [2024-11-27 16:17:39,234] ERROR Uncaught exception in REST call to /admin/loggers/root (org.apache.kafka.connect.runtime.rest.errors.ConnectExceptionMapper:65) java.lang.UnsupportedOperationException: null at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:142) ~[?:?] at java.base/java.util.ImmutableCollections$AbstractImmutableCollection.add(ImmutableCollections.java:147) ~[?:?] at org.apache.kafka.connect.runtime.Loggers.loggers(Loggers.java:156) ~[connect-runtime-4.0.0-SNAPSHOT.jar:?] at org.apache.kafka.connect.runtime.Loggers.setLevel(Loggers.java:132) ~[connect-runtime-4.0.0-SNAPSHOT.jar:?] at org.apache.kafka.connect.runtime.AbstractHerder.setWorkerLoggerLevel(AbstractHerder.java:1186) ~[connect-runtime-4.0.0-SNAPSHOT.jar:?] at org.apache.kafka.connect.runtime.rest.resources.LoggingResource.setLevel(LoggingResource.java:132) ~[connect-runtime-4.0.0-SNAPSHOT.jar:?] ``` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org