添加依赖
<dependency>
<groupId>uk.org.lidalia</groupId>
<artifactId>sysout-over-slf4j</artifactId>
<version>1.0.2</version>
</dependency>
如果下载不下来,需要手动下载
下載地址
https://mvnrepository.com/artifact/uk.org.lidalia/sysout-over-slf4j/1.0.2
新建目录
mavenLib\uk\org\lidalia\sysout-over-slf4j\1.0.2
spring boot 使用
package com.zfl.config;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J;
/**
* 将 System.out 输出到 slf4j中
*/
@Component
public class SysoutOverSlf4jRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
}
web.xml 使用
<listener>
<listener-class>uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4JServletContextListener</listener-class>
</listener>