package log4jTest.com; import java.io.FileReader; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; public interface log4jDemo { public static void main(String[] args) { Logger logger = Logger.getLogger(log4jDemo.class); //使用默认的配置信息,不需要写log4j.properties BasicConfigurator.configure(); //设置日志输出级别为info,这将覆盖配置文件中设置的级别 logger.setLevel(Level.INFO); //下面的消息将被输出 logger.info("this is an info"); logger.warn("this is a warn"); logger.error("this is an error"); logger.fatal("this is a fatal"); } }
package log4jTest.com; import java.io.FileReader; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; public interface log4jDemo { public static void main(String[] args) { Logger logger = Logger.getLogger(log4jDemo.class); SimpleLayout layout=new SimpleLayout(); FileAppender appender=null; try { //把输出端配置到F:/logs/log.log appender = new FileAppender(layout,"F:/logs/log.log",false); }catch(Exception e){ e.printStackTrace(); } logger.addAppender(appender);//添加输出端 logger.setLevel((Level)Level.DEBUG);//覆盖配置文件中的级别 logger.info("this is an info"); logger.warn("this is a warn"); logger.error("this is an error"); logger.fatal("this is a fatal"); } }
一直都报这个这就有点痛苦了,下面的配置文件加上红色的就ok了,具体原因不解