tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mel Martinez <>
Subject Re: I have got a query regarding PrintWriter,
Date Mon, 02 Apr 2001 17:30:18 GMT

--- Anil <> wrote:
> I have been trying to intercept all the System.out
> and System.err request
> given in the tomcat. Here is the excerpts of the
> Code.
> I wrote a class WSPrintStream that extends
> PrintStream and overided the
> commonly used println(..) statements.

[definition of WSPrintStream trimmed except
to note that it is implemented by overriding
each println() method to fire a PropertyChangeEvent.]
> >>>>>>>
> now before the execution of tomcat server I added
> this code
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> oldSystem_out = System.out;
> WSPrintStream wsp = new
> WSPrintStream(System.out);
> System.setOut(wsp);
> wsp.addPropertyChangeListener(this);

> Now I can catch all the println statements in the
> >>>>>>>public void  
> propertyChange(
> java.beans.PropertyChangeEvent evt){
> when ever the System.out.println(....) is used in
> System
> But,,
> This is a problem I  encountered
> If I use
> >>>>>>>>>> pw = new 
>     ;
>            pw.println("helo try reading this");

Umm... just curious, but why not use 
instead of wrapping it here?  Since (according
to your use of System.setOut(), then the following
be true:

    System.out instanceof WSPrintStream
and System.out.println() -> WSPrintStream.println()

this is not the real, problem though (see below).

> I am not able to catch the message from going to the
> default out put 
> stream.
> i.e my WSPrintStream does not get invoked.

Your WSPrintStream subclass needs to override the 
write(byte b) method.  When you wrap one OutputStream 
around another, the data is passed from one stream to 
another through the OutputStream write() method.  
The println() method is not part of OutputStream
and so as far as the wrapping PrintStream object is 
concerned they (your println methods) do not exist.

I hope this helps.


Dr. Mel Martinez
G1440, Inc.

Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.

View raw message