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/09 03:02:51 UTC

Writing my own valve to do extra logging

Hi, I have found that I need to write my own access logging mechanism
to work with Tomcat.  I need the ability to log to a database and do
other things that the built-in mechanism simply can't do.  Extremely
good database-searchable real-time logging is critical to this project.

One way to do this is to write a logging filter.  Unfortunately this
doesn't give me all the info I need.  I need to be able to capture all
response codes, content length, etc.  Even if I write a class that
extends HttpServletResponseWrapper and use a filter to use that
response object, it doesn't catch all the info I need (trust me, I've
tried this).

So my solution is to write a valve which will replace the built-in
org.apache.catalina.valves.AccessLogValve valve.  It's very easy to
write a valve, but in this case, I simply copied the catalina valve,
adjusted import directives so it would compile, compiled it, and put
it in CATALINA/server/lib/mylogger.jar.

Then I edited bin/catalina.sh so that mylogger.jar was on the java
classpath, and edited server.xml so that instead of <Valve
className="org.apache.catalina.AccessLogValve" it was <Valve
className="kz.sidereal.valves.AccessLogValve"

At that point I restarted the server and in catalina.out, I got an
exception:

Exception during startup processing
java.lang.reflect.InvocationTargetException: java.lang.NoClassDefFoundError: org/apache/catalina/valves/ValveBase
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
        at org.apache.catalina.loader.StandardClassLoader.loadClass(Unknown Source)
        at org.apache.catalina.loader.StandardClassLoader.loadClass(Unknown Source)
        at org.apache.catalina.loader.StandardClassLoader.loadClass(Unknown Source)
        at org.apache.catalina.loader.StandardClassLoader.loadClass(Unknown Source)

I have no idea what I'm doing wrong here.  Does anyone have any ideas
on how to replace this particular valve so that I can write my own
logger?

Thanks for any tips.

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