Reputation: 1092
I've got a Spring Boot application with the following log4j2.xml config file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="MyFile" fileName="getworks-backend.log" immediateFlush="false" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="Console" level="warn"/>
<AppenderRef ref="MyFile" level="warn"/>
</Root>
</Loggers>
And I've got a warn message writing like
log.warn("Unexpected token {}", accessToken);
It appears on the console, but not in my log file.
If I change AppenderRef ref="MyFile" level="warn"
level to level="info"
it writes log messages to file, but only those that were not written by loggers in my classes.
Some parts of my build.gradle:
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
dependencies {
//log4j2
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.11.0'
//other dependencies
}
How can I make log4j2 not to ignore my logs while writing to file?
P.S . I am using @Log4j2
lombok annotation to generate my log
object, but if I am doing it in classic way nothing changes.
Upvotes: 0
Views: 548
Reputation: 2047
Since you have set immediateFlush=false, the output is buffered. Eventually the output will be flushed after more messages, but I would remove that statement. ImmediateFlush is true by default.
Upvotes: 2