不同的包路径,采用不同的 appender 及日志文件进行记录有2种方法
第一种:
修改配置文件:
XX.AName为包名
XX.BName为包名
log4j.logger.XX.AName=DEBUG,A1
log4j.additivity.XX.AName=false
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.MaxFileSize=5120KB
log4j.appender.A1.MaxBackupIndex=20
log4j.appender.A1.File=${user.dir}/log/A1.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %t%r%5p %c\:%L - %m%n
---------------------------------------------------------------------------------------------------------
log4j.logger.XX.BName=DEBUG,A2
log4j.additivity.XX.BName=false
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.MaxFileSize=5120KB
log4j.appender.A2.MaxBackupIndex=20
log4j.appender.A2.File=${user.dir}/log/A2.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %t%r%5p %c\:%L - %m%n
第二种方法:
程序控制:
CC为随意名称
log4j.logger.CC=DEBUG,CC1
log4j.additivity.CC=false
log4j.appender.CC1=org.apache.log4j.RollingFileAppender
log4j.appender.CC1.MaxFileSize=5120KB
log4j.appender.CC1.MaxBackupIndex=20
log4j.appender.CC1.File=${user.dir}/log/A1.log
log4j.appender.CC1.layout=org.apache.log4j.PatternLayout
log4j.appender.CC1.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %t%r%5p %c\:%L - %m%n
org.apache.commons.logging.Log LOGGER = LogFactory.getLog("CC");
LOGGER .debug("XXXXX");
其他资料连接
http://blog.csdn.net/azheng270/archive/2008/03/12/2173430.aspx