java - Log4j 2 root logger overrides everything? -
i relatively new log4j 2. currently, have 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 log in these 2 classes consolemain , clientmain via static logger
static logger _logger = logmanager.getlogger(clientmain.class.getname());
and
static logger _logger = logmanager.getlogger(consolemain.class.getname());
they use appender , level of root logger. if level of root logger "error" above, never shows debug level logging output, if level of individual loggers debug. also, appends log file specified in root logger , not 1 specified in logger of classes.
so, seems root logger somehow overrides everything. how log4j use appender , level of loggers of classes?
i tried removing appender of root, not log anything.
thank you!
i tried setup cannot reproduce issue. here code used:
package com.messaging.main; import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger; public class clientmain { public static void main(string[] args) throws exception { logger logger = logmanager.getlogger(clientmain.class); logger.debug("debug clientmain"); } } package com.messaging.main; import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger; public class consolemain { public static void main(string[] args) throws exception { logger logger = logmanager.getlogger(consolemain.class); logger.debug("debug consolemain"); } }
when run these exact config file following output:
benchmark.log:
07:59:51.070 [main] debug com.messaging.main.clientmain - debug clientmain
debug.log:
07:59:51.070 [main] debug com.messaging.main.clientmain - debug clientmain 07:59:58.306 [main] debug com.messaging.main.consolemain - debug consolemain 07:59:58.306 [main] debug com.messaging.main.consolemain - debug consolemain
this expected behaviour. duplicate entries normal default additivity true in log4j, both root logger , named loggers log same message (see http://logging.apache.org/log4j/2.x/manual/configuration.html#additivity). i'm not seeing issue reporting debug-level messages never appear in log file when root level "error".
perhaps else going on. version of log4j2 using (most recent beta9)? can try reproduce issue bare minimum sample code above , see if issue still occurs?
Comments
Post a Comment