log4j配置的方法
1. 在Classpath里面增加一个log4j.properties的文件
2.在文件中写入
?
log4j.rootCategory=INFO,testlog4j.appender.test=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.test.DatePattern=yyyyMMddlog4j.appender.test.Append=truelog4j.appender.test.File=D:\\test.loglog4j.appender.test.layout=org.apache.log4j.PatternLayoutlog4j.appender.test.layout.ConversionPattern=%d{MM/dd HH:mm:ss} %x:[%p] %c{1}: %m%n?
?
3. 写一个测试类:
?
import org.apache.log4j.Logger;public class test {public static Logger log = Logger.getLogger(test.class);public static void main(String args[]){log.info("info");log.error("hello11111111111111111111");}}?
执行这个类后,会在D盘生成test.log的文件。
?
Log4j有四种形式的输出INFO,DEBUG,ERROR和FATAL。
?
其中DEBUG的级别是独立的。
?
其他三种的级别从高到低分别是: FATAL>ERROR>INFO
?
?