|
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="AccessLogDBValve"
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,
ts TIMESTAMP NOT NULL,
remoteHost CHAR(15) NOT NULL,
user 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 (ts),
INDEX (remoteHost),
INDEX (virtualHost),
INDEX (query),
INDEX (userAgent)
);
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.
author: Andre de Jesus author: Peter Rossbach |