出现了这个问题是说少依赖加入以下依赖即可:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
想整合slf4j+log4j要加入以下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
spring-boot-starter-log4j包括了一下几个包:
然后在resouces文件夹下新建log4j.properties
log4j.rootCategory=info,file_info,file_error,stdout
log4j.logger.org.springframework.web.filter.CommonsRequestLoggingFilter=debug,file_info,stdout
log4j.additivity.org.springframework.web.filter.CommonsRequestLoggingFilter=false
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-ddHH:mm:ss}%-5p%c{1}:%L-%m%n
log4j.appender.file_info=org.apache.log4j.RollingFileAppender
log4j.appender.file_info.layout=org.apache.log4j.PatternLayout
log4j.appender.file_info.MaxFileSize=100MB
log4j.appender.file_info.MaxBackupIndex=10
log4j.appender.file_info.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss}[%-5p](%-30c{1})[TxId:%X{PtxId},SpanId:%X{PspanId}][ET:%X{ENV_TYPE},AN:%X{APP_NAME},SN:%X{SERVICE_NAME},CN:%X{CONTAINER_NAME},CI:%X{CONTAINER_IP}]%m%n
log4j.appender.file_info.Threshold=DEBUG
log4j.appender.file_info.append=true
log4j.appender.file_info.File=//Users/xiaweiyi/Downloads/demo/logs/log4j.log
log4j.appender.file_error=org.apache.log4j.RollingFileAppender
log4j.appender.file_error.layout=org.apache.log4j.PatternLayout
log4j.appender.file_error.MaxFileSize=100MB
log4j.appender.file_error.MaxBackupIndex=10
log4j.appender.file_error.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss}[%-5p](%-30c{1})[TxId:%X{PtxId},SpanId:%X{PspanId}][ET:%X{ENV_TYPE},AN:%X{APP_NAME},SN:%X{SERVICE_NAME},CN:%X{CONTAINER_NAME},CI:%X{CONTAINER_IP}]%m%n
log4j.appender.file_error.Threshold=ERROR
log4j.appender.file_error.append=true
log4j.appender.file_error.File=/Users/xiaweiyi/Downloads/demo/logs/log4j.log
路径按需要改即可