logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Serodio <dan...@checkforte.com.br>
Subject RE: ConsoleAppender and System.{out,err}.println
Date Wed, 23 Oct 2002 15:36:56 GMT
On Wed, 2002-10-23 at 11:57, Cakalic, James wrote:
> Every implementation of PrintStream (the class of System.out) that I have ever reviewed
synchronized on itself (the object) around the actual I/O. So all the public print, println,
and flush methods are synchronized. Whenever one of these methods is called, the output will
be written uninterrupted by another call. 
> 
> Any problem would be when multiple PrintStream calls are used to write the detail for
a single event seeing as each call would be independent (synchronization-wise) of every other
call. ConsoleAppender relies on its WriterAppender superclass implemetation of append which
ultimately makes one write call with the result of the layout format and then, if the layout
ignoresThrowable, gets a String[] representing the Throwable and writes each String with a
separate write call followed by a separate write of the LINE_SEPARATOR. So, depending on your
layout, there could be quite a variance of opportunity for a non-log4j writer to jump in.

	Thank you, your explanation made things very clear to me.
 
> An Appender introduces another level of synchronization so that multiple Loggers using
the same Appender cannot collide. So, if it is possible, the suggestion to use LoggingOutputStream
to replace the PrintStream represented by System.out (see the javadoc) is probably a good
way to minimize the collision between ConsoleAppender and System.out users. 

	Actually, I'm currently using LoggingOutputStream and want to get rid
of it because of the possible infinite recursion when LogLog tries to
log stuff. It's already happened in my app, so for me it's not only a
possibility, but an actual problem.
 
> Of course, ultimately, you'll want to replace all the System.out calls :-)

	Of course, that's my future goal. :)
 
> Best regards,
> Jim Cakalic
> 
> -----Original Message-----
> From: Ceki Gülcü [mailto:ceki@qos.ch]
> Sent: Tuesday, October 22, 2002 3:16 PM
> To: Log4J Users List
> Subject: Re: ConsoleAppender and System.{out,err}.println
> 
> 
> 
> AFAIK, System.out.println is synchronized.
> 
> At 16:19 22.10.2002 -0300, Daniel Serodio wrote:
> >I'm maintaining a Java app with tons of System.out.println's all around,
> >and I'm using log4j in my (new) code.
> >
> >If I setup log4j to use a ConsoleAppender, will log4j's and println's
> >output be intermixed in a predictible way? I mean, will each log message
> >be logged until EOL at least?
> >
> >Does anyone have any suggestions for using System.out.println and log4j
> >together in the same app?
> >
> >Thanks in advance
> >--
> >[]'s
> >Daniel Serodio
> 
> --
> Ceki
> 
> TCP implementations will follow a general principle of robustness: be
> conservative in what you do, be liberal in what you accept from
> others. -- Jon Postel, RFC 793
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>
> 
> 
> <font size="1">Confidentiality Warning:  This e-mail contains information intended
only for the use of the individual or entity named above.  If the reader of this e-mail is
not the intended recipient or the employee or agent responsible for delivering it to the intended
recipient, any dissemination, publication or copying of this e-mail is strictly prohibited.
The sender does not accept any responsibility for any loss, disruption or damage to your data
or computer system that may occur while using data contained in, or transmitted with, this
e-mail.   If you have received this e-mail in error, please immediately notify us by return
e-mail.  Thank you.
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>
-- 
[]'s
Daniel Serodio


--
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