一个典型的log4j.properties的书写
log4j.rootCategory=FATAL, stdout,rfa //这里配置日志记录的级别,常用的有fatal,error,warn,info,debug,trace(全部大写)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n
//下面配置记录文件以及文件个数,大小
log4j.appender.rfa=org.apache.log4j.RollingFileAppender
log4j.appender.rfa.File=c:/mylog.txt
log4j.appender.rfa.MaxFileSize=1MB
log4j.appender.rfa.MaxBackupIndex=5
log4j.appender.rfa.layout=org.apache.log4j.PatternLayout
log4j.appender.rfa.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss} %-5p %c - %m%n
在java 类里面这样写记录:
Log log=LogFactory.getLog(LoginAction.class);
log.fatal("fatal... "+name+" = "+password);
log.error("error... "+name+" = "+password);
log.warn("warn... "+name+" = "+password);
log.info("info... "+name+" = "+password);
log.debug("debug... "+name+" = "+password);
log.trace("trace... "+name+" = "+password);