java 控制台 System.out日志输出到logback文件里

使用spring boot2.0.7开发项目,由于调用了其他组c++的本地方法,他们的日志是直接在控制台打印日志的,而我们这边统一用logback记录日志,然后logback配置后控制台的日志没有记录到日志文件,不好排查问题,于是找到了一个插件,简单配置即可。http://projects.lidalia.org.uk/sysout-over-slf4j/quickstart.html

 

Quick Start

Add sysout-over-slf4j to the classpath

Download the sysout-over-slf4j-1.0.2.jar on the Downloads page.

Alternatively, add the following to your maven pom dependencies:

<dependency>
        <groupId>uk.org.lidalia</groupId>
        <artifactId>sysout-over-slf4j</artifactId>
        <version>1.0.2</version>
</dependency>

In a Standalone Application

Make the following call as early as possible in the startup of your application:

SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

In a Servlet Container

Add the following to your web.xml:

<listener>
  <listener-class>uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4JServletContextListener</listener-class>
</listener>

版权声明:本文为yckiven原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。