mod_log_dbd is a module for Apache 2.2+ that writes access logs to a database using the APR DBD framework. It's designed for simplicity and speed, and therefore lacks some of the features of other logging modules. It does however automatically create any needed tables and columns.
NOTE: At the moment MySQL and PostgreSQL are the only supported databases because I don't know the magic config strings for the other databases supported by DBD. If you know what they are please tell me.
Features
- Store access logs in database tables
- Configurable columns (similar to mod_log_config's format specifiers)
- Automatically creates tables and columns (when given sufficient privileges)
To Do
- Log cookies
- Log specific header lines
- Handle internal redirects
- Possibly log server time automatically (ignore format specifier)
- Add support for a TIMESTAMP column to log database time
- Discover magic config strings for databases other than MySQL and PostgreSQL
- Add "magic" format specifiers for commonly used formats
- Add a means to specify "All columns, except..."
- Store logs in a file if the database isn't available
License
mod_log_dbd is Copyright 2006-2007 by Brandon Fosdick and released under the BSD License.
Download
Latest Version (v0.2)
Installation
-
FreeBSD
As root...
- cd /usr/ports/www/mod_log_dbd
- make install clean
- Restart Apache
- Linux, etc
- Extract the archive
- cd mod_log_dbd-0.1
- ./configure --with-mysql=[path] --with-apache=[path]
- apxs -i -a -n log_dbd mod_log_dbd.la
- Restart Apache
Configuration
This module was designed for simplicity and therefore doesn't allow the nearly-inifinite customization of other logging modules. For example, column and table names are created automatically, which not only simplifies configuration but improves performance as well.
LogDBD Directive
| Description | Enable the module and specify a DSN |
|---|---|
| Syntax | LogDBD driver://user:password@hostname:port/[socket_path/]dbname |
| Default | LogDBD Off |
| Context | server config, virtual host |
The LogDBD directive enables the module for a given server or virtual host and specifies a DSN for the database to write to. If specified in the top server config it will be inherited by all virtual hosts, but can still be overriden in each virtual host.
NOTE: At the moment MySQL and PostgreSQL are the only supported databases because I don't know the magic config strings for the other databases supported by DBD. If you know what they are please tell me.
LogDBDFormat Directive
| Description | Specify the information to be logged |
|---|---|
| Syntax | LogDBDFormat "format" |
| Default | All columns are logged |
| Context | server config, virtual host |
The LogDBDFormat directive specifies which columns to log using the single character format specifiers listed below. If not specified, or given an empty string, all columns will be logged.
Column Specifiers
Most of the column specifiers are similar to the format specifiers used by mod_log_config. When using PostgreSQL, the "INT UNSIGNED" columns are actually "INT" because PostgreSQL doesn't support unsigned.
| Specifier | Column Name | Column Type | Description | |
|---|---|---|---|---|
| t | RequestTime | DATETIME | Time the request was received | |
| B | BytesSent | INT UNSIGNED | Size of response in bytes, excluding HTTP headers | |
| D | ElapsedSeconds | INT UNSIGNED | Request duration in seconds | |
| d | ElapsedMicoSeconds | INT UNSIGNED | Request duration in microseconds | |
| P | ChildPID | INT | The process ID of the child that serviced the request | |
| p | ServerPort | INT UNSIGNED | The canonical port of the server serving the request | |
| s | Status | INT UNSIGNED | Status. For requests that got internally redirected, this is the status of the *original* request. | |
| I | BytesIn | INT UNSIGNED | Bytes received, including request and headers, cannot be zero. | |
| O | BytesOut | INT UNSIGNED | Bytes sent, including headers, cannot be zero. | |
| A | Agent | VARCHAR(255) | Equivalent to %{User-agent}i | |
| a | RemoteIP | VARCHAR(255) | Remote IP-address | |
| f | RequestFile | VARCHAR(255) | Filename | |
| H | RequestProtocol | VARCHAR(255) | The request protocol | |
| h | RemoteHost | VARCHAR(255) | Remote host | |
| i | UniqueID | VARCHAR(255) | Unique request ID | |
| l | RemoteLogname | VARCHAR(255) | Remote logname (from identd, if supplied) | |
| m | RequestMethod | VARCHAR(255) | The request method | |
| q | RequestArgs | TEXT | The query string | |
| R | Referer | VARCHAR(255) | Referer | |
| r | RequestLine | TEXT | First line of request | |
| u | RemoteUser | VARCHAR(255) | Remote user (from auth; may be bogus if return status (%s) is 401) | |
| U | RequestURI | TEXT | The URL path requested, not including any query string | |
| v | VirtualHost | VARCHAR(255) | The canonical ServerName of the server serving the request | |
| V | ServerName | VARCHAR(255) | The server name according to the UseCanonicalName setting |
History
Version 0.3 - Released ??
- Default to logging equivalent of "NCSA combined IO" when no columns specified
Version 0.2 - Released April 18, 2007
- Added support for logging bytes sent and received (I and O columns)
- Added support for PostgreSQL
- Added support for local sockets
- Changed UniqueID column specifier fom 'I' to 'i'
- Default to logging equivalent of "NCSA combined" when no columns specified
Version 0.1 - Released January 23, 2007
- Initial Release
- Lots of rough edges, need feedback (and more time)