logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: How to overwrite System.out in ConsoleAppender?
Date Tue, 11 Jun 2002 19:53:37 GMT
At 14:25 11.06.2002 -0500, Michael Roytman wrote:
>Hi,
>
>this seems like a simple thing but I can't get it to work.
>I have some JUnit tests that test my logging service that uses
>log4j 1.1.3. I need to capture ConsoleAppender output in order to
>do the JUnit assert that logging output contains what's expected.
>
>I reset System.out to my own PrintStream and then get it's content
>to see if it contains the expected log statement.
>
>     public void resetStdout() {
>         out = new ByteArrayOutputStream();
>         System.setOut(new PrintStream(out));
>     }
>
>     public String getStdout() {
>         return out.toString();
>     }

I reckon that a ConsoleAppender instance is created and attached to a 
logger *before* you call resetStdout(). You have to instantiate a new 
ConsoleAppender each time you reset the console.

>Michael

--
Ceki

SUICIDE BOMBING - A CRIME AGAINST HUMANITY
Sign the petition: http://www.petitiononline.com/1234567b
I am signatory number 22106. What is your number?


--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message