现象:
log4j:WARN Please initialize the log4j system properly.
log4j:WARN No appenders could be found for logge
log4j出现此种打印说明,log4j无论是经过xml配置还是属性文件配置,都没有得到很好的配置,所以,打印出来initialize the log4j system properly。借鉴了网上的一些解决办法, 对于单元测试来讲未免过于复杂,对于有时仅是要可以支持打印到console控制台即可,贡献下面简单代码给大家方便拷贝借用:)
Properties properties = new Properties();
properties.setProperty("log4j.rootLogger","DEBUG, Console");
properties.setProperty("log4j.appender.Console","org.apache.log4j.ConsoleAppender");
properties.setProperty("log4j.appender.Console.layout","org.apache.log4j.PatternLayout");
properties.setProperty("log4j.appender.Console.layout.ConversionPattern","(%r ms) [%t] %-5p: %c#%M %x: %m%n");
PropertyConfigurator.configure(properties);