99package maru.test.cluster
1010
1111import org.apache.logging.log4j.Level
12- import org.apache.logging.log4j.LogManager
13- import org.apache.logging.log4j.core.LoggerContext
14- import org.apache.logging.log4j.core.appender.ConsoleAppender
12+ import org.apache.logging.log4j.core.config.Configurator
1513import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
14+ import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration
1615
1716fun configureLoggers (
1817 pattern : String = "%d{yyyy-MM -dd HH : mm : ss} [%level] - %msg | %logger{36}%n",
@@ -31,18 +30,17 @@ fun configureLoggers(
3130) {
3231 val builder = ConfigurationBuilderFactory .newConfigurationBuilder()
3332
34- // Create pattern layout
33+ // Create console appender with custom pattern
34+ val appenderBuilder =
35+ builder
36+ .newAppender(" Console" , " CONSOLE" )
37+ .addAttribute(" target" , " SYSTEM_OUT" )
38+
3539 val layoutBuilder =
3640 builder
3741 .newLayout(" PatternLayout" )
3842 .addAttribute(" pattern" , pattern)
39-
40- // Create console appender
41- val appenderBuilder =
42- builder
43- .newAppender(" Console" , " CONSOLE" )
44- .addAttribute(" target" , ConsoleAppender .Target .SYSTEM_OUT )
45- .add(layoutBuilder)
43+ appenderBuilder.add(layoutBuilder)
4644
4745 builder.add(appenderBuilder)
4846
@@ -51,21 +49,18 @@ fun configureLoggers(
5149 builder
5250 .newRootLogger(rootLevel)
5351 .add(builder.newAppenderRef(" Console" ))
54-
5552 builder.add(rootLoggerBuilder)
5653
57- // Add specific logger configurations
54+ // Configure specific loggers
5855 logLevels.forEach { (loggerName, level) ->
59- builder.add(
56+ val loggerBuilder =
6057 builder
6158 .newLogger(loggerName, level)
59+ .addAttribute(" additivity" , false )
6260 .add(builder.newAppenderRef(" Console" ))
63- .addAttribute(" additivity" , false ),
64- )
61+ builder.add(loggerBuilder)
6562 }
6663
67- // Apply configuration
68- val ctx = LogManager .getContext(false ) as LoggerContext
69- ctx.configuration = builder.build()
70- ctx.updateLoggers()
64+ val configuration: BuiltConfiguration = builder.build()
65+ Configurator .initialize(configuration)
7166}
0 commit comments