Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ loxx Public

PHP tool to import Apache log files into a database

Notifications You must be signed in to change notification settings

bmack/loxx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loxx

A PHP CLI tool to import Apache web server log files into a SQL database for analysis and debugging.

Features

  • 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

Installation

composer install

Configuration

Edit 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.

Usage

Basic Import

php loxx.php import data/access.log

Uses the default "combined" Apache log format.

Import with Preset Format

php loxx.php import data/access.log --format-preset my-custom-preset

Available presets can be defined in

Import with Custom Format

php loxx.php import data/access.log --format '%h %l %u %t "%r" %>s %b'

Custom Table Name

php loxx.php import data/access.log --table my_logs

Without this option, the table name is generated from the filename and timestamp.

Apache Log Format Codes

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.

Examples

Import with Combined Format

php loxx.php import /var/log/apache2/access.log --format-preset combined

Import with Custom Headers

php loxx.php import app.log \
  --format '%{X-Forwarded-For}i %l %u %t %r %>s %b %D "%{Referer}i" "%{User-Agent}i"' \
  --table app_logs

Database Schema

Each import creates a new table with:

  • Auto-increment id column
  • One column per log field (auto-named from format)
  • imported_at timestamp column

Requirements

  • PHP 8.1 or higher
  • Composer
  • SQLite or MySQL database

Development

Running Tests

# 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 --testdox

The 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

License

MIT

About

PHP tool to import Apache log files into a database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages