My Log4j2 config file looks like:
<Appenders>
<RollingRandomAccessFile name="APP_LOG_APPENDER" fileName="${sys:baseLogPath}/${appLogFileName}.log"
filePattern="${sys:baseLogPath}/backups/$${date:yyyy-MM}/${appLogFileName}-%d{yyyy-MM-dd}-%i.log.gz" immediateFlush="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [Thread: %t] %level [%c][%M] - %msg%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="50 MB" />
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="APP_LOG_APPENDER" />
</Root>
</Loggers>
Logger statements in class MyClass
public class MyClass {
private final static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MyClass.class);
public void someMethod() {
logger.debug("Some sample string at DEBUG level....");
logger.info("Some sample string at INFO level....");
logger.warn("Some sample string at WARN level....");
logger.error("Some sample string at ERROR level....");
}
}
The log messages are coming out as:
2016-04-11 12:32:31.245 [Thread: main] DEBUG [com.demo.MyClass][] - Some sample string at DEBUG level....
2016-04-11 12:32:31.245 [Thread: main] INFO [com.demo.MyClass][] - Some sample string at INFO level....
2016-04-11 12:32:31.245 [Thread: main] WARN [com.demo.MyClass][] - Some sample string at WARN level....
2016-04-11 12:32:31.245 [Thread: main] ERROR [com.demo.MyClass][] - Some sample string at ERROR level....
I am using log4j2-2.5 version and corresponding SLF4J API.
Could someone help me understand why is this happening?