This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch 4.0
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/4.0 by this push:
     new d3791c39e3e KAFKA-18831 Migrating to log4j2 introduce behavior changes 
of adjusting level dynamically (#18969)
d3791c39e3e is described below

commit d3791c39e3e426161ea4f8fd95ca3c97b049dd95
Author: TengYao Chi <[email protected]>
AuthorDate: Fri Feb 21 16:12:58 2025 +0800

    KAFKA-18831 Migrating to log4j2 introduce behavior changes of adjusting 
level dynamically (#18969)
    
    fix the following behavior changes.
    
    1) in log4j 1, users can't change the logger by parent if the logger is 
declared by properties explicitly. For example, `org.apache.kafka.controller` 
has level explicitly in the properties. Hence, we can't use 
"org.apache.kafka=INFO" to change the level of `org.apache.kafka.controller` to 
INFO. By contrast, log4j2 allows us to change all child loggers by the parent 
logger.
    
    2) in log4j2, we can change the level of root to impact all loggers' level. 
By contrast, log4j 1 can't.
    
    Reviewers: Chia-Ping Tsai <[email protected]>
---
 core/src/main/scala/kafka/utils/Log4jController.scala | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/core/src/main/scala/kafka/utils/Log4jController.scala 
b/core/src/main/scala/kafka/utils/Log4jController.scala
index 4bc022dadfe..61573b878cc 100755
--- a/core/src/main/scala/kafka/utils/Log4jController.scala
+++ b/core/src/main/scala/kafka/utils/Log4jController.scala
@@ -76,11 +76,11 @@ object Log4jController {
     val level = Level.toLevel(logLevel.toUpperCase(Locale.ROOT))
 
     if (loggerName == ROOT_LOGGER) {
-      Configurator.setAllLevels(LogManager.ROOT_LOGGER_NAME, level)
+      Configurator.setLevel(LogManager.ROOT_LOGGER_NAME, level)
       true
     } else {
       if (loggerExists(loggerName) && level != null) {
-        Configurator.setAllLevels(loggerName, level)
+        Configurator.setLevel(loggerName, level)
         true
       }
       else false
@@ -88,12 +88,13 @@ object Log4jController {
   }
 
   def unsetLogLevel(loggerName: String): Boolean = {
+    val nullLevel: Level = null
     if (loggerName == ROOT_LOGGER) {
-      Configurator.setAllLevels(LogManager.ROOT_LOGGER_NAME, null)
+      Configurator.setLevel(LogManager.ROOT_LOGGER_NAME, nullLevel)
       true
     } else {
       if (loggerExists(loggerName)) {
-        Configurator.setAllLevels(loggerName, null)
+        Configurator.setLevel(loggerName, nullLevel)
         true
       }
       else false

Reply via email to