java文件中:
private static Logger logger = Logger.getLogger(UserUtil.class);
logger.error("数据库查询失败", e);
log4j.properties文件中
log4j.rootLogger=INFO,A2,stdout
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=${catalina.base}/logs/user_manage.log
log4j.appender.A2.Append=true
log4j.appender.A2.MaxFileSize=4096KB
log4j.appender.A2.MaxBackupIndex=10
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
###[%-5p] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t][%x] %C{8}@(%F:%L):%m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %m%n