public class MyTestListener implements ApplicationListener<ApplicationStartingEvent> {
private static final Logger logger = LoggerFactory.getLogger(MyTestListener.class);
@Override
public void onApplicationEvent(ApplicationStartingEvent event) {
logger.info("MyTestListener run.....");
//todo--my logic
}
}
I have a listener named MyTestListener. It seems that 'logger.info("MyTestListener run.....");' will not log .
MyEnv:
spring boot: 2.5.9
logback: 1.2.3
Comment From: wilkinsona
You can't easily do so as the logging system isn't fully initialized until the ApplicationEnvironmentPreparedEvent has been published. Until that time, logging is suppressed. If you really want to log in your listener, you may be able to use a org.springframework.boot.logging.DeferredLog that you replay later on.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.