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

查看:439
本文介绍了将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天全站免登陆