|
发表于 2020-3-1 16:30:01
|
显示全部楼层
拷貝一個log4j或者編寫一個log4j放到WEB-INF/classes下
log4j內容如:
------------------------------------------------------------------------------------
log4j.rootCategory=DEBUG,stdout,R
# Set the level to DEBUG if you want to log all SlideExceptions (some of them aren't errors)
log4j.category.org.apache.slide.common.SlideException=FATAL
########################################
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
#log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%4p [%t] %c - %m%n
log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %-20c{2} - %m %n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logger.log
log4j.appender.R.ImmediateFlush=true
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
#log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
#log4j.appender.R.layout.ConversionPattern=%4p [%t] %c - %m%n
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} [%t] %-5p %-30c{3} %x - %m %n
使用如:
import org.apache.log4j.Logger;
然后你需要在类的开头写上下面一句
private final static Logger log =
Logger.getLogger(ClassName.class);//注意这里写的是当前类的类名。
这样你就有了一个日志对象叫做 log,这个log有以下集中用法
log.info();//一般信息
log.debug();//调试信息
log.error();//错误信息
log.warn();//警告信息
log.fatal();//致命错误信息 |
|