You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Glenn Nielsen <gl...@voyager.apg.more.net> on 2002/05/21 15:01:11 UTC

[PROPOSAL] Tomcat 4 System.err/System.out logging

Problem
-------

Frequently code running within a web application context will print
to System.out, System.err, printStackTrace(), etc.  This output ends
up getting logged to catalina.out without any timestamps. When
you have multiple virtual hosts/contexts it can be a pain to correlate
the stack traces and other output in catalina.out with the web application
context which generated it.

Proposed Solution
-----------------

1.  Create a JNDI named resource for the ServletContext
    (java:comp/env/context) scoped to the web application.

2.  Create a custom PrintStream object which uses the above
    JNDI named resource to find which ServletContext to direct
    output to.  If no context is found, it prints to the default
    System.err and System.out.  If a ServletContext is found it uses
    its log method for output.

3.  On Tomcat startup use System.setErr() and System.setOut() to
    replace the default PrintStream with the above custom PrintStream.


Comments, suggestions, and alternate solutions are welcome. :-)

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Andrew Houghton <aa...@volunteermatch.org>.
Wouldn't this introduce a dependency on Tomcat JARs for Jasper 2?  I can 
think of at least one project off hand that uses Jasper standalone; it 
seems a shame to change this, since Jasper 2 is currently engine-agnostic.

- a.

Glenn Nielsen wrote:
> I have taken the org.apache.jasper.util.SystemLogHandler Remy wrote
> and put it in org.apache.tomcat.util.log.SystemLogHandler.
> 
> I refactored it so that the PrintStreams and Byte arrays are recycle.
> Plus implemented a stack so that there can be nested usage.
> 
> Finally, I implemented it in Tomcat 4 so that any System.out or System.err
> output generated when handling a request is sent to the appropriate
> web application context log.
> 
> Remy, you may want to switch jasper2 over to using this, then remove
> org.apache.jasper.util.SystemLogHandler.
> 
> Glenn
> 
> Remy Maucherat wrote:
> 
>>>Remy Maucherat wrote:
>>>
>>>How is Ant implemented within Tomcat for doing JSP compiles?
>>>
>>>I am concerned about Ant running within the same JVM and having to capture
>>>the JVM's System.out and System.err.  Other output from catalina could get
>>>intermixed with the Ant output.  Also I saw something about synchronizing
>>>of compiles being required.
>>
>>If the compiler is run within the same thread as the request, then the
>>filtering can be done.
>>I presume all out of process compilers would suffer from that problem.
>>
>>However, I'd like to point out that there's no other choice but to upgrade.
>>In many situations, the current Jasper 2 generated servlets don't compile to
>>valid bytecode when using the classic compiler (and you get a VerifyError
>>when loading the class; this happens esp when using JSTL). The J2SE team
>>hasn't touched the old compiler code for more than 2 years, and refuse to
>>fix bugs :-(
>>
>>Remy
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Andrew Houghton
aah@volunteermatch.org


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
I have taken the org.apache.jasper.util.SystemLogHandler Remy wrote
and put it in org.apache.tomcat.util.log.SystemLogHandler.

I refactored it so that the PrintStreams and Byte arrays are recycle.
Plus implemented a stack so that there can be nested usage.

Finally, I implemented it in Tomcat 4 so that any System.out or System.err
output generated when handling a request is sent to the appropriate
web application context log.

Remy, you may want to switch jasper2 over to using this, then remove
org.apache.jasper.util.SystemLogHandler.

Glenn

Remy Maucherat wrote:
> 
> > Remy Maucherat wrote:
> >
> > How is Ant implemented within Tomcat for doing JSP compiles?
> >
> > I am concerned about Ant running within the same JVM and having to capture
> > the JVM's System.out and System.err.  Other output from catalina could get
> > intermixed with the Ant output.  Also I saw something about synchronizing
> > of compiles being required.
> 
> If the compiler is run within the same thread as the request, then the
> filtering can be done.
> I presume all out of process compilers would suffer from that problem.
> 
> However, I'd like to point out that there's no other choice but to upgrade.
> In many situations, the current Jasper 2 generated servlets don't compile to
> valid bytecode when using the classic compiler (and you get a VerifyError
> when loading the class; this happens esp when using JSTL). The J2SE team
> hasn't touched the old compiler code for more than 2 years, and refuse to
> fix bugs :-(
> 
> Remy
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 
----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Pier Fumagalli <pi...@betaversion.org>.
"Remy Maucherat" <re...@apache.org> wrote:

>> Remy Maucherat wrote:
>> 
>> How is Ant implemented within Tomcat for doing JSP compiles?
>> 
>> I am concerned about Ant running within the same JVM and having to capture
>> the JVM's System.out and System.err.  Other output from catalina could get
>> intermixed with the Ant output.  Also I saw something about synchronizing
>> of compiles being required.
> 
> If the compiler is run within the same thread as the request, then the
> filtering can be done.
> I presume all out of process compilers would suffer from that problem.
> 
> However, I'd like to point out that there's no other choice but to upgrade.
> In many situations, the current Jasper 2 generated servlets don't compile to
> valid bytecode when using the classic compiler (and you get a VerifyError
> when loading the class; this happens esp when using JSTL). The J2SE team
> hasn't touched the old compiler code for more than 2 years, and refuse to
> fix bugs :-(

I'm wondering how hard it would be to use BCEL associated with some extended
JavaCC grammar for JSPs... Bah...

    Pier


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Remy Maucherat <re...@apache.org>.
> Remy Maucherat wrote:
>
> How is Ant implemented within Tomcat for doing JSP compiles?
>
> I am concerned about Ant running within the same JVM and having to capture
> the JVM's System.out and System.err.  Other output from catalina could get
> intermixed with the Ant output.  Also I saw something about synchronizing
> of compiles being required.

If the compiler is run within the same thread as the request, then the
filtering can be done.
I presume all out of process compilers would suffer from that problem.

However, I'd like to point out that there's no other choice but to upgrade.
In many situations, the current Jasper 2 generated servlets don't compile to
valid bytecode when using the classic compiler (and you get a VerifyError
when loading the class; this happens esp when using JSTL). The J2SE team
hasn't touched the old compiler code for more than 2 years, and refuse to
fix bugs :-(

Remy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.

Remy Maucherat wrote:

>>Problem
>>-------
>>
>>Frequently code running within a web application context will print
>>to System.out, System.err, printStackTrace(), etc.  This output ends
>>up getting logged to catalina.out without any timestamps. When
>>you have multiple virtual hosts/contexts it can be a pain to correlate
>>the stack traces and other output in catalina.out with the web application
>>context which generated it.
>>
>>Proposed Solution
>>-----------------
>>
>>1.  Create a JNDI named resource for the ServletContext
>>    (java:comp/env/context) scoped to the web application.
>>
>>2.  Create a custom PrintStream object which uses the above
>>    JNDI named resource to find which ServletContext to direct
>>    output to.  If no context is found, it prints to the default
>>    System.err and System.out.  If a ServletContext is found it uses
>>    its log method for output.
>>
>>3.  On Tomcat startup use System.setErr() and System.setOut() to
>>    replace the default PrintStream with the above custom PrintStream.
>>
>>
>>Comments, suggestions, and alternate solutions are welcome. :-)
>>
> 
> There's a (small) problem. The new compiler (needed for Jasper 2) and Ant
> require that the Sys.err (and/or Sys.out) is captured to actually display
> error messages.
> That proposal must be modified to allow temporarily capturing a thread's
> Sys.out output, and put it in a String (in addition to the logging features
> you mentioned).
> 
> Since this class is needed in Jasper (for other components, it's just an
> enhancement), it must be independent of Catalina (your proposal seems to be
> ok for that) and should be put in j-t-c/util.
> 
> To summarize, that's a great timing for your proposal (I have the Ant
> compiler working at the moment, but I still need to do the output capture)
> :)
>



How is Ant implemented within Tomcat for doing JSP compiles?

I am concerned about Ant running within the same JVM and having to capture
the JVM's System.out and System.err.  Other output from catalina could get
intermixed with the Ant output.  Also I saw something about synchronizing
of compiles being required.

 
> Remy
> 

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by Remy Maucherat <re...@apache.org>.
> Problem
> -------
>
> Frequently code running within a web application context will print
> to System.out, System.err, printStackTrace(), etc.  This output ends
> up getting logged to catalina.out without any timestamps. When
> you have multiple virtual hosts/contexts it can be a pain to correlate
> the stack traces and other output in catalina.out with the web application
> context which generated it.
>
> Proposed Solution
> -----------------
>
> 1.  Create a JNDI named resource for the ServletContext
>     (java:comp/env/context) scoped to the web application.
>
> 2.  Create a custom PrintStream object which uses the above
>     JNDI named resource to find which ServletContext to direct
>     output to.  If no context is found, it prints to the default
>     System.err and System.out.  If a ServletContext is found it uses
>     its log method for output.
>
> 3.  On Tomcat startup use System.setErr() and System.setOut() to
>     replace the default PrintStream with the above custom PrintStream.
>
>
> Comments, suggestions, and alternate solutions are welcome. :-)

There's a (small) problem. The new compiler (needed for Jasper 2) and Ant
require that the Sys.err (and/or Sys.out) is captured to actually display
error messages.
That proposal must be modified to allow temporarily capturing a thread's
Sys.out output, and put it in a String (in addition to the logging features
you mentioned).

Since this class is needed in Jasper (for other components, it's just an
enhancement), it must be independent of Catalina (your proposal seems to be
ok for that) and should be put in j-t-c/util.

To summarize, that's a great timing for your proposal (I have the Ant
compiler working at the moment, but I still need to do the output capture)
:)

Remy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [PROPOSAL] Tomcat 4 System.err/System.out logging

Posted by John Trollinger <ja...@trollingers.com>.
The other problem with logging is that messages logged without a trace
level are not given a default trace level so there is no way to stop
those messages from being displayed.  Why are messages not given a
default log level if they are not created with one.

John

-----Original Message-----
From: glenn@zathras.earthdome.org [mailto:glenn@zathras.earthdome.org]
On Behalf Of Glenn Nielsen
Sent: Tuesday, May 21, 2002 8:01 AM
To: tomcat-dev@jakarta.apache.org
Subject: [PROPOSAL] Tomcat 4 System.err/System.out logging


Problem
-------

Frequently code running within a web application context will print to
System.out, System.err, printStackTrace(), etc.  This output ends up
getting logged to catalina.out without any timestamps. When you have
multiple virtual hosts/contexts it can be a pain to correlate the stack
traces and other output in catalina.out with the web application context
which generated it.

Proposed Solution
-----------------

1.  Create a JNDI named resource for the ServletContext
    (java:comp/env/context) scoped to the web application.

2.  Create a custom PrintStream object which uses the above
    JNDI named resource to find which ServletContext to direct
    output to.  If no context is found, it prints to the default
    System.err and System.out.  If a ServletContext is found it uses
    its log method for output.

3.  On Tomcat startup use System.setErr() and System.setOut() to
    replace the default PrintStream with the above custom PrintStream.


Comments, suggestions, and alternate solutions are welcome. :-)

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>