No appenders could be found for logger(log4j)?

前端 未结 30 2689
[愿得一人]
[愿得一人] 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:04

    First import:

     import org.apache.log4j.PropertyConfigurator;
    

    Then add below code to main method:

    String log4jConfPath ="path to/log4j.properties";
    PropertyConfigurator.configure(log4jConfPath);
    

    Create a file at path to and add the below code to that file.

    log4j.rootLogger=INFO, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
    

提交回复
热议问题