You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2014/01/12 16:54:51 UTC

[jira] [Reopened] (LOG4J2-481) Stream-Interface for Loggers

     [ https://issues.apache.org/jira/browse/LOG4J2-481?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma reopened LOG4J2-481:
--------------------------------


Re-opening, as a failing JUnit test revealed a problem when running on Windows.

The test that fails is {{LoggerTest.getStream()}} "Message should be blank-ish". The expected value is {{" DEBUG "}}, but the actual value of {{results.get(2)}} is {{" DEBUG \r"}} on Windows.

I think this is happening because the line separator on Windows is {{"\r\n"}}, and the {{LoggerStream}} class only works correctly if the line separator is {{"\n"}}. Probably both of these methods in {{LoggerStream$HelperStream}} are incorrect as it looks like they only trim off the trailing {{"\n"}} character, which leaves a trailing {"\r"}} character on Windows:
{code}
@Override
public synchronized void write(int b) {
    super.write(b);
    if (b == '\n') {
        log(count - 1);
    }
}

@Override
public synchronized void write(byte[] b, int off, int len) {
    super.write(b, off, len);
    int newLine = lastIndexOf('\n');
    if (newLine != -1) {
        log(newLine);
    }
}
{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
>             Fix For: 2.0-rc1
>
>         Attachments: 0001-Add-LoggerStream-and-tests.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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org