This Apache module will permit you to log to a SQL database; it can log each access request as well as data associated with each request: cookies, notes, and inbound/outbound headers. Unlike logging to a flat text file - which is standard in Apache - a SQL-based log exhibits tremendous flexibility and power of data extraction. (See section 4.1.1 in the FAQ for further discussion and examples of the advantages to SQL.)
This module can either replace or happily coexist with mod_log_config, Apache's text file logging facility. In addition to being more configurable than the standard module, mod_log_sql is much more flexible.
This project was formerly known as ``mod_log_mysql.'' It was renamed ``mod_log_sql'' in order to reflect the project goal of database-inspecificity. The module currently supports MySQL, but support for other database backends is underway.
In order to save speed and overhead, links are kept alive in between queries. This module uses one dedicated SQL link per httpd child, opened by each child process when it is born. Among other things, this means that this module supports logging into only one MySQL server, and for now, also, only one SQL database. But that's a small tradeoff compared to the blinding speed of this module. Error reporting is robust throughout the module and will inform the administrator of database issues in the Apache ERRORLOG for the server/virtual server.
Virtual hosts are supported in the same manner they are in the regular logging modules. The administrator defines some basic 'global' directives in the main server config, then defines more specific 'local' directives inside each VirtualHost stanza.
A robust "preserve" capability has now been implemented. This permits the module to preserve any failed INSERT commands to a local file on its machine. In any situation that the database is unavailable - e.g. the network fails or the database host is rebooted - mod_log_sql will note this in the error log and begin appending its log entries to the preserve file (which is created with the user & group ID of the running Apache process, e.g. "nobody/nobody" on many Linux installations). When database availablity returns, mod_log_sql seamlessly resumes logging to it. When convenient for the sysadmin, he/she can easily import the preserve file into the database because it is simply a series of SQL insert statements.
All the data that would be contained in the "Combined Log Format" is logged by default, plus a little extra. Your best bet is to begin by accepting this default, then later customize the log configuration based on your needs.
The documentation of the run-time directives includes a full explanation of what you can log, including examples - see section 3.6.
In MySQL 3.21 and above you can easily convert this to a human readable format using from_unixtime(), e.g.:
The actual logging code was taken from the already existing flat file text modules, so all that credit goes to the Apache Server group.
The MySQL routines and directives were added by Zeev Suraski <email@example.com>.
All changes from 1.06+ and the new documentation were added by Chris Powell <firstname.lastname@example.org>. It seems that the module had fallen into the "unmaintained" category - it hadn't been updated since 1998 - so Chris adopted it as the new maintainer.