A PHP CLI tool to import Apache web server log files into a SQL database for analysis and debugging.
- Parse Apache access and error logs using standard format codes
- Automatically create database tables from log file structure
- Support for SQLite and MySQL databases
- Batch import with progress tracking
- Configurable format presets for common log types
composer installEdit config.php to set your database connection:
'database' => 'sqlite://' . __DIR__ . '/loxx.db',
// or for MySQL:
// 'database' => 'mysql://user:password@localhost/dbname',Add custom format presets in the same file if needed.
php loxx.php import data/access.logUses the default "combined" Apache log format.
php loxx.php import data/access.log --format-preset my-custom-presetAvailable presets can be defined in
php loxx.php import data/access.log --format '%h %l %u %t "%r" %>s %b'php loxx.php import data/access.log --table my_logsWithout this option, the table name is generated from the filename and timestamp.
Common format codes supported:
%h- Remote host (IP address)%l- Remote logname%u- Remote user%t- Time of request%r- Request line (method, path, protocol)%>s- Status code%b- Response size in bytes%D- Request processing time (microseconds)%{Header}i- Request header (e.g.,%{User-Agent}i)
See the Apache mod_log_config documentation for all available codes.
php loxx.php import /var/log/apache2/access.log --format-preset combinedphp loxx.php import app.log \
--format '%{X-Forwarded-For}i %l %u %t %r %>s %b %D "%{Referer}i" "%{User-Agent}i"' \
--table app_logsEach import creates a new table with:
- Auto-increment
idcolumn - One column per log field (auto-named from format)
imported_attimestamp column
- PHP 8.1 or higher
- Composer
- SQLite or MySQL database
# Run all tests
composer test
# Run only unit tests
composer test:unit
# Run only integration tests
composer test:integration
# Run with detailed output
./vendor/bin/phpunit --testdoxThe test suite includes:
- Unit tests for Apache log parser and database manager
- Integration tests for the complete import workflow
- Test fixtures for common and combined log formats
MIT