I am trying to log some lines to a log files using logback. The file is correctly created and my console output is actually written in the log file.
Then, I inserted some logger.debug()
instructions in my code, which I don't find in my log. Why?
I am using Spring Boot:
@SpringBootApplication
public class MyApplication {
private static final Logger logger =
LoggerFactory.getLogger(MyApplication.class);
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean
InitializingBean myInitializer(final IdentityService identityService) {
return new InitializingBean() {
public void afterPropertiesSet() throws Exception {
logger.debug("Preparing things...");
if (someCondition) {
doSomething();
logger.debug("Done something.");
} else {
doSomethingElse();
logger.debug("Done something else.");
}
}
};
}
}
application.properties
includes logging.file=logs/mylog.log
and this file is created.
Logback configuration is very easy and it should be correct and correctly placed (if I change this file, e.g. by introducing a log file name pattern, it works):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
Why I don't see my log instructions in my log file? Is it because I am building an InitializingBean? How can I log these lines?