How to initialize log4j properly?

前端 未结 24 3579
太阳男子
太阳男子 2020-11-22 06:49

After adding log4j to my application I get the following output every time I execute my application:

log4j:WARN No appenders could be found for logger (slideselec         


        
24条回答
  •  情书的邮戳
    2020-11-22 06:59

    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.

提交回复
热议问题