复制和重定向System.err流 [英] Copy and Redirecting System.err Stream

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

问题描述

我目前在我的应用程序中使用java.util.logger。它将其输出发送到System.err。我需要它继续这样做,但我还需要将该输出发送到其他东西。

I am currently using java.util.logger in my application. It sends its output to System.err. I need it to continue to do this, but I also need to send that output to something else.

有没有办法复制System.err流以便它可以发送到两个不同的来源吗?

Is there a way to copy the System.err stream so that it can send to two different sources?

推荐答案

一如既往注意人们引用 java.util.logger 我倾向于至少建议查看另一个日志库,例如 logback 和< a href =http://www.slf4j.org/ =nofollow> slf4j 。

As always when note people referencing java.util.logger I feel inclined to at least recommend looking at another logging library, such as logback and slf4j.

博客文章描述一种方法,可以很容易地适应,以支持你所要求的。简而言之,您需要做的是定义一个可以复制其输出的PrintStream,使用以下命令进行分配:

This blog post describes a method which can easily be adapted to support what you're asking for. In short what you need to do is define a PrintStream which can duplicate its output, assign this using:

System.setErr(doubleLoggingPrintStream)

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

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