引入依赖:
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency>
配置log4j.properties:
log4j.rootLogger=debug,stdout,DEBUG,ERROR
#console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= [%d{yyyy-MM-dd HH:mm:ss a}]:%p %l%m%n
#debug 按大小及个数打印
log4j.logger.DEBUG=DEBUG
log4j.appender.DEBUG=org.apache.log4j.RollingFileAppender
log4j.appender.DEBUG.File=${catalina.home}/logs/ftptool_debug.log
log4j.appender.DEBUG.Threshold=DEBUG
log4j.appender.DEBUG.MaxFileSize=20MB
log4j.appender.DEBUG.MaxBackupIndex=10
log4j.appender.DEBUG.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [ Class:%c >> Method: %l ]%n%p:%m%n
#error 按日期打印
log4j.logger.ERROR=ERROR
log4j.appender.ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERROR.File=${catalina.home}/logs/ftptool_error.log
log4j.appender.ERROR.DatePattern='.'yyyy-MM-dd
log4j.appender.ERROR.Threshold=ERROR
log4j.appender.ERROR.Append=true
log4j.appender.ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n