No appenders could be found for logger(log4j)?

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

    This Short introduction to log4j guide is a little bit old but still valid.

    That guide will give you some information about how to use loggers and appenders.


    Just to get you going you have two simple approaches you can take.

    First one is to just add this line to your main method:

    BasicConfigurator.configure();
    

    Second approach is to add this standard log4j.properties (taken from the above mentioned guide) file to your classpath:

    # Set root logger level to DEBUG and its only appender to A1.
    log4j.rootLogger=DEBUG, A1
    
    # A1 is set to be a ConsoleAppender.
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    
    # A1 uses PatternLayout.
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
    

提交回复
热议问题