ppkarwasz commented on code in PR #17373:
URL: https://github.com/apache/kafka/pull/17373#discussion_r1824026165


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Loggers.java:
##########
@@ -174,43 +175,50 @@ 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();
+        Set<String> loggerNames = loggerConfigs.stream()
+            .map(LoggerConfig::getName)
+            .collect(Collectors.toSet());
+
+        List<org.apache.logging.log4j.Logger> loggers = new ArrayList<>();
+        for (String name : loggerNames) {
+            loggers.add(LogManager.getLogger(name));
+        }
+        return loggers;
     }
 
     // visible for testing
-    org.apache.log4j.Logger rootLogger() {
+    org.apache.logging.log4j.Logger rootLogger() {
         return LogManager.getRootLogger();
     }
 
-    private void setLevel(org.apache.log4j.Logger logger, Level level) {
-        Level currentLevel = logger.getLevel();
-        if (currentLevel == null)
-            currentLevel = logger.getEffectiveLevel();
+    private void setLevel(org.apache.logging.log4j.Logger logger, Level level) 
{
+        String loggerName = logger.getName();
+        LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        LoggerConfig loggerConfig = 
context.getConfiguration().getLoggerConfig(loggerName);
+        Level currentLevel = loggerConfig.getLevel();

Review Comment:
   This looks pretty much as a maintenance headache for the Apache Kafka team. 
What will happen if the user switches logging implementation (at least 3 
logging implementations are supported by the Log4j API, see [logging 
implementations](https://logging.apache.org/log4j/2.x/manual/installation.html#impl))?
   
   It looks to me that you only use this for JMX. If that is the case, Log4j 
Core provides an [out-of-the-box JMX 
support](https://logging.apache.org/log4j/2.x/manual/jmx.html). You just need 
to enable it, since JMX is a potential source of security problems and is 
disabled by default.
   
   If you need to get and set the levels for other reasons, please open a 
thread on `dev@logging`. Users like to change logger levels programmatically so 
often, that we'd better offer an implementation independent API for that.



-- 
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

Reply via email to