--- Anil <[EMAIL PROTECTED]> 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
the
> System
>
> But,,
>
>
> This is a problem I encountered
> If I use
> >>>>>>>>>> java.io.PrintStream pw = new
> java.io.PrintStream(System.out);
> pw.println("helo try reading this");
>>>>>>
Umm... just curious, but why not use
System.out.println("helo...");
instead of wrapping it here? Since (according
to your use of System.setOut(), then the following
should
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
interface
and so as far as the wrapping PrintStream object is
concerned they (your println methods) do not exist.
I hope this helps.
Cheers,
Dr. Mel Martinez
G1440, Inc.
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/?.refer=text