chia7712 commented on code in PR #20249:
URL: https://github.com/apache/kafka/pull/20249#discussion_r2297926717


##########
core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java:
##########
@@ -69,6 +69,21 @@ public void applyChangesForResource(
         }
     }
 
+    /**
+     * Alters the log level configurations for specified loggers.
+     * <p>
+     * This method allows modifying log levels for individual loggers via 
{@link AlterableConfig}
+     * operations (SET or DELETE). Valid log levels are restricted to 
constants defined in {@link LogLevelConfig}.
+     * <p>
+     *
+     * @param ops A collection of {@link AlterableConfig} objects, where each 
object specifies:
+     * <ul>           
+     *   <li> name: The logger name to configure.
+     *   <li> value: The log level (must be a valid {@link LogLevelConfig} 
constant).
+     *   <li> configOperation: The operation type (SET or DELETE).
+     * </ul>
+     * @throws InvalidConfigurationException if the log level is not valid.
+     */
     void alterLogLevelConfigs(Collection<AlterableConfig> ops) {

Review Comment:
   We’re now working on changing the broker logger level, and the code might 
look like this:
   ```java
   admin.incrementalAlterConfigs(
       Map.of(
           new ConfigResource(Type.BROKER_LOGGER, "2"),
           List.of(new AlterConfigOp(new ConfigEntry(log.getName, "TRACE"), 
OpType.SET))
       )
   );
   ```
   But in fact, the server enforces a validation check on these strings:
   ```java
   if (!LogLevelConfig.VALID_LOG_LEVELS.contains(logLevel)) {
       throw new InvalidConfigurationException(
           "Cannot set the log level of " + loggerName + " to " + logLevel +
           " as it is not a supported log level. Valid log levels are " + 
VALID_LOG_LEVELS_STRING
       );
   }
   ```
   That’s why I think we should encourage users not to rely on magic strings 
like `TRACE`. Instead, they should use constants such as 
`LogLevelConfig.TRACE_LOG_LEVEL`. After all, `LogLevelConfig` is a proper 
public API.
   
   Another interesting point is that many Kafka contributors may not even be 
aware of `LogLevelConfig`. I noticed that in many tests, people directly write 
`DEBUG`, `TRACE`, etc., rather than referencing `LogLevelConfig`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to