java.lang.Objectorg.apache.catalina.valves.ValveBase
org.apache.catalina.valves.JDBCAccessLogValve
All Implemented Interfaces:
Lifecycle, Valve, MBeanRegistration, Contained
This Tomcat extension logs server access directly to a database, and can be used instead of the regular file-based access log implemented in AccessLogValve. To use, copy into the server/classes directory of the Tomcat installation and configure in server.xml as:
<Valve className="org.apache.catalina.valves.JDBCAccessLogValve" driverName="your_jdbc_driver" connectionURL="your_jdbc_url" pattern="combined" resolveHosts="false" />
Many parameters can be configured, such as the database connection (with
driverName and connectionURL),
the table name (tableName)
and the field names (corresponding to the get/set method names).
The same options as AccessLogValve are supported, such as
resolveHosts and pattern ("common" or "combined"
only).
When Tomcat is started, a database connection (with autoReconnect option) is created and used for all the log activity. When Tomcat is shutdown, the database connection is closed. This logger can be used at the level of the Engine context (being shared by all the defined hosts) or the Host context (one instance of the logger per host, possibly using different databases).
The database table can be created with the following command:
CREATE TABLE access ( id INT UNSIGNED AUTO_INCREMENT NOT NULL, remoteHost CHAR(15) NOT NULL, userName CHAR(15), timestamp TIMESTAMP NOT NULL, virtualHost VARCHAR(64) NOT NULL, method VARCHAR(8) NOT NULL, query VARCHAR(255) NOT NULL, status SMALLINT UNSIGNED NOT NULL, bytes INT UNSIGNED NOT NULL, referer VARCHAR(128), userAgent VARCHAR(128), PRIMARY KEY (id), INDEX (timestamp), INDEX (remoteHost), INDEX (virtualHost), INDEX (query), INDEX (userAgent) );
Set JDBCAccessLogValve attribute useLongContentLength="true" as you have more then 4GB outputs. Please, use long SQL datatype at access.bytes attribute. The datatype of bytes at oracle is number and other databases use bytes BIGINT NOT NULL.
If the table is created as above, its name and the field names don't need to be defined.
If the request method is "common", only these fields are used:
remoteHost, user, timeStamp, query, status, bytes
TO DO: provide option for excluding logging of certain MIME types.
Andre - de JesusPeter - Rossbach| Field Summary | ||
|---|---|---|
| protected boolean | useLongContentLength | Use long contentLength as you have more 4 GB output.
|
| protected String | connectionName | The connection username to use when trying to connect to the database. |
| protected String | connectionPassword | The connection URL to use when trying to connect to the database. |
| protected Driver | driver | Instance of the JDBC Driver class we use as a connection factory. |
| protected static String | info | The descriptive information about this implementation. |
| protected LifecycleSupport | lifecycle | The lifecycle event support for this component. |
| Fields inherited from org.apache.catalina.valves.ValveBase: |
|---|
| container, containerLog, info, next, sm, domain, oname, mserver, controller |
| Constructor: |
|---|
driverName = null; connectionURL = null; tableName = "access"; remoteHostField = "remoteHost"; userField = "userName"; timestampField = "timestamp"; virtualHostField = "virtualHost"; methodField = "method"; queryField = "query"; statusField = "status"; bytesField = "bytes"; refererField = "referer"; userAgentField = "userAgent"; pattern = "common"; resolveHosts = false; |
| Method from org.apache.catalina.valves.JDBCAccessLogValve Summary: |
|---|
| addLifecycleListener, close, findLifecycleListeners, getConnectionName, getConnectionPassword, getCurrentTimeMillis, getUseLongContentLength, invoke, open, removeLifecycleListener, setBytesField, setConnectionName, setConnectionPassword, setConnectionURL, setDriverName, setMethodField, setPattern, setQueryField, setRefererField, setRemoteHostField, setResolveHosts, setStatusField, setTableName, setTimestampField, setUseLongContentLength, setUserAgentField, setUserField, setVirtualHostField, start, stop |
| Methods from org.apache.catalina.valves.ValveBase: |
|---|
| backgroundProcess, createObjectName, event, getContainer, getContainerName, getController, getDomain, getInfo, getNext, getObjectName, getParentName, invoke, postDeregister, postRegister, preDeregister, preRegister, setContainer, setController, setNext, setObjectName, toString |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.catalina.valves.JDBCAccessLogValve Detail: |
|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TO DO: more flexible field choices. |
|
|
|
|
|
|
|
|
|
|
|
|
|