You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Dr. Evil" <dr...@sidereal.kz> on 2002/03/06 04:29:32 UTC

Writing a logging filter

I am trying to write a filter which will perform some custom logging
actions for my servlets.  It's pretty basic stuff.  I want to log the
browser IP, the browser User Agent, the response code and the response
content type and length.

The browser info is easy.  I can fetch all that from the Request
object.

The problem is finding out the content type, length and response code
from the Response object.  There appears to be no way of doing this.

How can I write my own logger for Tomcat?  Any sugestions would be
appreciated.


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Writing a logging filter

Posted by Joel Rees <jo...@alpsgiken.gr.jp>.
Dr. Evil wrote:

> I am trying to write a filter which will perform some custom logging
> actions for my servlets.  It's pretty basic stuff.  I want to log the
> browser IP, the browser User Agent, the response code and the response
> content type and length.
> 
> The browser info is easy.  I can fetch all that from the Request
> object.
> 
> The problem is finding out the content type, length and response code
> from the Response object.  There appears to be no way of doing this.
> 
> How can I write my own logger for Tomcat?  Any sugestions would be
> appreciated.

Does Jakarta's own Log4j not work for you?

Joel Rees
Alps Giken Kansai Systems Develoment
Suita, Osaka




--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Writing a logging filter

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 6 Mar 2002, Dr. Evil wrote:

> Date: 6 Mar 2002 03:29:32 -0000
> From: Dr. Evil <dr...@sidereal.kz>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Writing a logging filter
>
>
> I am trying to write a filter which will perform some custom logging
> actions for my servlets.  It's pretty basic stuff.  I want to log the
> browser IP, the browser User Agent, the response code and the response
> content type and length.
>
> The browser info is easy.  I can fetch all that from the Request
> object.
>
> The problem is finding out the content type, length and response code
> from the Response object.  There appears to be no way of doing this.
>
> How can I write my own logger for Tomcat?  Any sugestions would be
> appreciated.
>

Short answer:  Write a Filter that creates a response wrapper that
overrides the setContentType() and setContentLength() methods to capture
the values set by the application, and make them available via public
methods back to the filter.

Longer answer:  I answered this question in detail a few weeks ago,
complete with sample code.  Look in the mail archives for messages with
"filter" in them and you'll find it.

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>