logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Nyolt <a31bd...@freenet.de>
Subject Re: Log4j closes System.err
Date Mon, 28 Feb 2011 16:00:00 GMT
On 28/02/11 16:26, Christian Grobmeier wrote:
>>
>> activateOptions calls WriterAppender.setWriter(), which first calls reset(),
>> which in turn calls closeWriter().
>> see
>> https://svn.apache.org/repos/asf/logging/log4j/trunk/src/main/java/org/apache/log4j/WriterAppender.java
>> (the base class of ConsoleAppender containing all mentioned methods)
>
> yes, but its creating a new quiet writer afterwards. so you should be
> able to write to another stream, right?

No, in my case neither I nor log4j are able to write to System.err, have a look at the attached
code.

The expected output is (# denote writes to System.err, otherwise to System.out):

#Writing to System.err #1
configuring log4j
Test
#Writing to System.err #2
#ERROR [main]: Logging some message
Finished


But the output actually looks like:

#Writing to System.err #1
configuring log4j
Test
Finished


If I debug this application and configure Eclipse to break on any caught IOException, the
thread pauses with this StackTrace:

Thread [main] (Suspended (exception IOException))	
	PrintStream.ensureOpen() line: 275	
	PrintStream.write(String) line: 474	
	PrintStream.print(String) line: 619	
	PrintStream.println(String) line: 756	
	Log4jTest.main(String[]) line: 29	

PrintStream.ensureOpen() line 275 is «throw new IOException("Stream closed");»
Thus no output is made. The same is true for the logging statement, since it uses System.err,
too.

Martin

Mime
View raw message