No appenders could be found for logger(log4j)?

前端 未结 30 2312
[愿得一人]
[愿得一人] 2020-11-22 08:16

I have put log4j to my buildpath, but I get the following message when I run my application:

log4j:WARN No appenders could be found for logger (dao.hsqlmanag         


        
30条回答
  •  囚心锁ツ
    2020-11-22 09:03

    If log4j.properties is indeed on the classpath, you are using Spring Boot to make a WAR file for deployment to an app server, you are omitting a web.xml file in favour of Spring Boot's autoconfigure, and you are not getting any log messages whatsoever, you need to explicitly configure Log4j. Assuming you are using Log4j 1.2.x:

    public class AppConfig extends SpringBootServletInitializer {
    
        public static void main( String[] args ) {
            // Launch the application
            ConfigurableApplicationContext context = SpringApplication.run( AppConfig.class, args );
        }
    
        @Override
        protected SpringApplicationBuilder configure( SpringApplicationBuilder application ) {
            InputStream log4j = this.getClass().getClassLoader().getResourceAsStream("log4j.properties");
            PropertyConfigurator.configure(log4j);
            return application;
        }
    
    // Other beans as required...
    }
    

提交回复
热议问题