[
https://issues.apache.org/jira/browse/LOG4J2-481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13862509#comment-13862509
]
Matt Sicker commented on LOG4J2-481:
------------------------------------
The stream doesn't have to be flushed anymore now that it's looking for
newlines in the write() methods. The underlying PrintStream is using
auto-flush, too, so that'll flush for any new lines or multi-byte write()'s (at
least that's how JDK7 has it implemented).
As to why it's useful? It helps provide a bridge to legacy logging systems or
legacy code that doesn't use a logger. Plus, there's the handy hack for dumb
APIs as well.
{code:java}
PrintStream out = new PrintStream(logger.getStream(Level.INFO));
PrintStream err = new PrintStream(logger.getStream(Level.ERROR));
System.setOut(out);
System.setErr(err);
{code}
> Stream-Interface for Loggers
> ----------------------------
>
> Key: LOG4J2-481
> URL: https://issues.apache.org/jira/browse/LOG4J2-481
> Project: Log4j 2
> Issue Type: New Feature
> Components: API
> Affects Versions: 2.0-beta9
> Environment: Linux, Java 1.7
> Reporter: Joe Merten
> Attachments: Add_PrintStream_view_LOG4J2-481.patch,
> EventLoggerTest.patch
>
>
> I would like to have method (or class) to use a logger as a PrintStream, like
> e.g.:
> {quote}
> PrintStream Logger.getStream(Level level);
> {quote}
> or maybe like this
> http://www.java2s.com/Open-Source/Java/Testing/jacareto/jacareto/toolkit/log4j/LogOutputStream.java.htm
> (as I recently discovered, org.apache.commons.exec.LogOutputStream is doing
> different things).
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]