I am relatively new to Log4j 2. Currently, I have this configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="DebugFile" fileName="../../logs/debug.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name="BenchmarkFile" fileName="../../logs/benchmark.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Logger name="com.messaging.main.ConsoleMain" level="debug">
<AppenderRef ref="DebugFile"/>
</Logger>
<Logger name="com.messaging.main.ClientMain" level="debug">
<AppenderRef ref="BenchmarkFile"/>
</Logger>
<Root level="error">
<AppenderRef ref="DebugFile"/>
</Root>
</Loggers>
</Configuration>
If I log something in these two classes ConsoleMain and ClientMain via a static Logger
static Logger _logger = LogManager.getLogger(ClientMain.class.getName());
and
static Logger _logger = LogManager.getLogger(ConsoleMain.class.getName());
they ALWAYS use the appender and level of the root logger. If the level of the root logger is "error" as above, it never shows any debug level logging output, even if the level of the individual loggers is debug. Also, it always appends to the log file specified in the root logger and not the one specified in the logger of the classes.
So, it seems that the root logger somehow overrides everything. How do I get log4j to actually use the appender and the level of the loggers of the classes?
I tried removing the appender of the root, but then it does not log anything.
Thank you!