将 System.out 和 System.err 重定向到 slf4j [英] Redirect System.out and System.err to slf4j

查看:32
本文介绍了将 System.out 和 System.err 重定向到 slf4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 System.out/err.println 输出重定向到 slf4j.

I needed to redirect System.out/err.println outputs to slf4j.

我知道这不是正确记录日志的方法,但有一个外部库,可以记录到 System.out

I know that this is not the way to do logging properly but there is an external library, which logs to System.out

推荐答案

您可以使用 sysout-over-slf4j.

sysout-over-slf4j 模块允许用户将所有对 System.out 和 System.err 的调用重定向到 SLF4J 定义的记录器,其中包含 System.out.println(或类似的)的完全限定类的名称已在可配置级别进行调用.

The sysout-over-slf4j module allows a user to redirect all calls to System.out and System.err to an SLF4J defined logger with the name of the fully qualified class in which the System.out.println (or similar) call was made, at configurable levels.

如果您使用 Maven,请下载 jar 并将其添加到您的类路径中.

If you are not using Maven, download the jar and add it to your classpath.

或者,将其添加为 Maven 依赖项:

Alternatively, add it as a Maven dependency:

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

然后在应用程序启动时,调用:

Then at application startup, call:

SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

这篇关于将 System.out 和 System.err 重定向到 slf4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆