From 0284fef88515b0714cb3378e582ed095eef865bb Mon Sep 17 00:00:00 2001 From: majialong Date: Fri, 29 May 2026 01:29:16 +0800 Subject: [PATCH] MINOR: Move LoggingController log level resolution test to server --- .../test/scala/kafka/utils/LoggingTest.scala | 20 -------- .../server/logger/LoggingControllerTest.java | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 server/src/test/java/org/apache/kafka/server/logger/LoggingControllerTest.java diff --git a/core/src/test/scala/kafka/utils/LoggingTest.scala b/core/src/test/scala/kafka/utils/LoggingTest.scala index 761b276c400bd..e07087b73866b 100644 --- a/core/src/test/scala/kafka/utils/LoggingTest.scala +++ b/core/src/test/scala/kafka/utils/LoggingTest.scala @@ -17,13 +17,11 @@ package kafka.utils -import org.apache.kafka.server.logger.LoggingController import java.lang.management.ManagementFactory import javax.management.ObjectName import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue} -import org.slf4j.LoggerFactory class LoggingTest extends Logging { @@ -60,22 +58,4 @@ class LoggingTest extends Logging { assertEquals(logging.getClass.getName, logging.log.underlying.getName) } - - @Test - def testLoggerLevelIsResolved(): Unit = { - val controller = new LoggingController() - val previousLevel = controller.getLogLevel("kafka") - try { - controller.setLogLevel("kafka", "TRACE") - // Do some logging so that the Logger is created within the hierarchy - // (until loggers are used only loggers in the config file exist) - LoggerFactory.getLogger("kafka.utils.Log4jControllerTest").trace("test") - assertEquals("TRACE", controller.getLogLevel("kafka")) - assertEquals("TRACE", controller.getLogLevel("kafka.utils.Log4jControllerTest")) - assertTrue(controller.getLoggers.contains("kafka=TRACE")) - assertTrue(controller.getLoggers.contains("kafka.utils.Log4jControllerTest=TRACE")) - } finally { - controller.setLogLevel("kafka", previousLevel) - } - } } diff --git a/server/src/test/java/org/apache/kafka/server/logger/LoggingControllerTest.java b/server/src/test/java/org/apache/kafka/server/logger/LoggingControllerTest.java new file mode 100644 index 0000000000000..18b58e216c142 --- /dev/null +++ b/server/src/test/java/org/apache/kafka/server/logger/LoggingControllerTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.server.logger; + +import org.junit.jupiter.api.Test; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class LoggingControllerTest { + + @Test + public void testLoggerLevelIsResolved() { + LoggingController controller = new LoggingController(); + String loggerName = "org.apache.kafka"; + String childLoggerName = "org.apache.kafka.server.logger.LoggingControllerTest"; + String previousLevel = controller.getLogLevel(loggerName); + try { + controller.setLogLevel(loggerName, "TRACE"); + // Do some logging so that the Logger is created within the hierarchy + // (until loggers are used only loggers in the config file exist). + LoggerFactory.getLogger(childLoggerName).trace("test"); + assertEquals("TRACE", controller.getLogLevel(loggerName)); + assertEquals("TRACE", controller.getLogLevel(childLoggerName)); + assertTrue(controller.getLoggers().contains(loggerName + "=TRACE")); + assertTrue(controller.getLoggers().contains(childLoggerName + "=TRACE")); + } finally { + controller.setLogLevel(loggerName, previousLevel); + } + } +}