m1a2st commented on code in PR #24213:
URL: https://github.com/apache/kafka/pull/24213#discussion_r4577563208
##########
core/src/main/scala/kafka/docker/KafkaDockerWrapper.scala:
##########
Review Comment:
Both environment variables (`KAFKA_LOG4J_ROOT_LOGLEVEL` and
`KAFKA_TOOLS_LOG4J_LOGLEVEL`) only contain a log level. The Root created from
the environment variables never has anything in otherProperties, and this
change only reads envRoot.getLevel anyway.
We could therefore pass the level directly as an `Option[String]` instead of
wrapping it in a Root and then extracting it. This would allow us to remove
buildRootLogger and simplify generateDefaultLog4jConfig as well.
##########
core/src/test/scala/unit/kafka/docker/KafkaDockerWrapperTest.scala:
##########
@@ -473,6 +576,63 @@ class KafkaDockerWrapperTest {
assertEquals(mounted, actual)
}
+ @Test
+ def testPrepareToolsLog4jConfigsPreservesRootSettings(): Unit = {
+ val (defaultConfigsPath, mountedConfigsPath, finalConfigsPath) =
createDirs()
+
+ val envVars = Map("KAFKA_TOOLS_LOG4J_LOGLEVEL" -> "DEBUG")
+
+ val default =
+ """Configuration:
+ | Loggers:
+ | Root:
+ | level: "WARN"
+ | AppenderRef:
+ | - ref: "STDERR"""".stripMargin
+
+ Files.write(defaultConfigsPath.resolve("tools-log4j2.yaml"),
default.getBytes(StandardCharsets.UTF_8)).toFile.deleteOnExit()
+ Files.write(finalConfigsPath.resolve("tools-log4j2.yaml"),
"".getBytes(StandardCharsets.UTF_8)).toFile.deleteOnExit()
+
+ KafkaDockerWrapper.prepareToolsLog4j2Configs(defaultConfigsPath,
mountedConfigsPath, finalConfigsPath, envVars)
+
+ val source = scala.io.Source.fromFile(finalConfigsPath.toString +
"/tools-log4j2.yaml")
+ val actual = try source.mkString.trim finally source.close()
+ val expected =
+ """Configuration:
+ | Loggers:
+ | Root:
+ | level: "DEBUG"
+ | AppenderRef:
+ | - ref: "STDERR"""".stripMargin
+
+ assertEquals(expected, actual)
+ }
+
+ @Test
+ def testPrepareToolsLog4jConfigsWithEmptyLogLevel(): Unit = {
Review Comment:
`testPrepareToolsLog4jConfigsWithEmptyLogLevel` seems to cover the same case
as `testGetToolsLog4jConfigsFromEnvWithEmptyEnvVariable`. I think we can
combine these two tests.
--
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]