Download the PHP package sl-projects/laravel-request-logger without Composer
On this page you can find all versions of the php package sl-projects/laravel-request-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sl-projects/laravel-request-logger
More information about sl-projects/laravel-request-logger
Files in sl-projects/laravel-request-logger
Package laravel-request-logger
Short Description A Laravel package to log all incoming HTTP requests
License MIT
Informations about the package laravel-request-logger
Laravel Request Logger
A high-performance Laravel package for logging and analyzing HTTP requests with minimal overhead. Built with a cache-first approach and normalized database structure for efficient storage and querying.
NOTE: This package has no connection with the Laravel framework or its creators. It is an independent project developed by Sofiane Lasri, mainly for educational purposes.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- For Laravel 11+ (New Structure)
- For Laravel 10 and Earlier
- Usage
- Advanced Features
- Database Schema
- Performance Considerations
- Testing
- Contributing
- License
Features
- ๐ High Performance: Cache-first approach ensures zero impact on request processing
- ๐ Normalized Database: Efficient storage with deduplicated entities (IPs, URLs, User Agents, MIME types)
- ๐ Async Processing: Background job processing for database persistence
- ๐ Rich Data Capture: Logs IP addresses, HTTP methods, status codes, response times, and more
- ๐ GeoIP Support: Automatic country code detection from IP addresses
- ๐ ๏ธ Fully Configurable: Customize cache TTL, storage keys, and processing behavior
- ๐งช 100% Tested: Comprehensive test coverage with factories for all models
- ๐ Thread-Safe: Cache locking prevents race conditions in high-traffic scenarios
Requirements
- PHP 8.2 or higher
- Laravel 11.9+ (with support for Laravel 12)
- Redis or Memcached recommended for caching (fallback to file cache supported)
Installation
Install the package via Composer:
Run the migrations to create the necessary database tables:
(Optional) Publish the configuration file for customization:
Configuration
For Laravel 11+ (New Structure)
Laravel 11 introduced a new application structure with simplified configuration. Here's how to set up the package:
1. Register Middleware
In bootstrap/app.php
:
2. Schedule the Command
In routes/console.php
:
For Laravel 10 and Earlier
For Laravel versions 10 and below, use the traditional configuration approach:
1. Register Middleware
In app/Http/Kernel.php
:
2. Schedule the Command
In app/Console/Kernel.php
:
Usage
Basic Usage
Once configured, the package automatically logs all incoming requests. The middleware captures request data in the terminate()
method to ensure zero impact on response times.
Selective Logging
Apply middleware to specific routes only:
Manual Processing
Process cached requests manually without waiting for the scheduler:
Querying Logged Requests
Advanced Features
Configuration Options
After publishing the config file, you can customize:
Custom Processing
Create custom processors for specific request types:
Event Listeners
The package dispatches events you can listen to:
Database Schema
The package uses a normalized database structure for optimal performance:
Tables
logged_requests
: Main table containing request records with foreign keysip_addresses
: Deduplicated IP addresses with country codesuser_agents
: Deduplicated user agent stringsmime_types
: Deduplicated MIME typesurls
: Deduplicated URL paths
Indexes
All foreign key columns and frequently queried fields are properly indexed for optimal query performance.
Performance Considerations
Cache Strategy
- Requests are initially stored in cache to avoid blocking the response
- Background job processes cached requests in batches
- Model ID caching prevents repeated database lookups
Optimization Tips
- Use Redis/Memcached: File-based cache can be slow under high load
- Adjust Batch Size: Larger batches reduce database calls but use more memory
- Schedule Frequency: Run
save:requests
more frequently under high traffic - Database Indexes: Ensure all foreign keys are properly indexed
- Pruning Old Data: Regularly clean old records to maintain performance
Testing
Run the test suite:
Run static analysis:
The package includes comprehensive tests for:
- Middleware functionality
- Job processing
- Model relationships and factories
- Command execution
- Cache operations
Contributing
Contributions are welcome! Since this is my first package, I would appreciate any feedback, suggestions, or improvements you can provide.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please ensure all tests pass and add tests for new features.
License
This package is open-source software licensed under the MIT license.
Author
Developed by Sofiane Lasri.
For any inquiries or suggestions, feel free to create an issue on GitHub.