Skip to content

Commit

Permalink
KAFKA-18831 Migrating to log4j2 introduce behavior changes of adjusti…
Browse files Browse the repository at this point in the history
…ng 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 <chia7712@gmail.com>
  • Loading branch information
frankvicky authored Feb 21, 2025
1 parent acea35d commit d31cbf5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/scala/kafka/utils/LoggingController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,25 @@ private class Log4jCoreController extends LoggingControllerDelegate {
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
}
}

override 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
Expand Down

0 comments on commit d31cbf5

Please sign in to comment.