参考了网上的资料,log4j配置文件,xml格式的 ,实现了分级输出文件,并可以对具体的包进行输出限制。 <? xml version="1.0" encoding="GB2312" ?> <! DOCTYPE log4j:configuration SYSTEM "log4j.dtd" > <!-- #log4j中有5级logger ,#FATAL 0 ,#ERROR 3 ,#WARN 4 ,#INFO 6 ,#DEBUG 7 --> < log4j:configuration xmlns:log4j ='http://jakarta.apache.org/log4j/'> <!--输出到控制台-- > < appender name ="LOG.Console" class ="org.apache.log4j.ConsoleAppender" > < layout class ="org.apache.log4j.PatternLayout" > < param name ="ConversionPattern" value ="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" /> </ layout > </ appender > <!-- 将级别为DEBUG的信息输出到控制台 --> < appender name ="LOG.DEBUG" class ="org.apache.log4j.RollingFileAppender" > < param name ="File" value ="d:/log/debug.log" /> < param name ="MaxFileSize" value ="5120KB" /> < param name ="MaxBackupIndex" value ="10" /> < layout class ="org.apache.log4j.PatternLayout" > < param name ="ConversionPattern" value ="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" /> </ layout > < filter class ="org.apache.log4j.varia.LevelRangeFilter"