No appenders could be found for logger(log4j)?

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

    As explained earlier there are 2 approaches

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

    BasicConfigurator.configure();
    

    Second approach is to add this standard log4j.properties file to your classpath:

    While taking second approach you need to make sure you initialize the file properly, Eg.

    Properties props = new Properties();
    props.load(new FileInputStream("log4j property file path"));
    props.setProperty("log4j.appender.File.File", "Folder where you want to store log files/" + "File Name");
    

    Make sure you create required folder to store log files.

提交回复
热议问题