mellivora / logger-factory
A modern logger factory library based on Monolog for PHP 8.3+, with seamless Laravel integration
Installs: 478
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 1
Forks: 3
Open Issues: 0
pkg:composer/mellivora/logger-factory
Requires
- php: >=8.3.0
 - monolog/monolog: ^3.0
 - psr/log: ^3.0
 
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.82
 - illuminate/config: ^10.0|^11.0|^12.0
 - illuminate/console: ^10.0|^11.0|^12.0
 - illuminate/container: ^10.0|^11.0|^12.0
 - illuminate/http: ^10.0|^11.0|^12.0
 - illuminate/support: ^10.0|^11.0|^12.0
 - phpoption/phpoption: ^1.9
 - phpunit/phpunit: ^11.0 || ^12.0
 - symfony/mailer: ^7.0
 
Suggests
- illuminate/console: ^10.0|^11.0|^12.0 - Required for Laravel commands
 - illuminate/http: ^10.0|^11.0|^12.0 - Required for Laravel middleware
 - illuminate/support: ^10.0|^11.0|^12.0 - Required for Laravel integration
 
- dev-master
 - v2.0.3-alpha
 - v2.0.2-alpha
 - v2.0.1-alpha
 - v2.0.0
 - v2.0.0-alpha
 - v1.1.2
 - v1.1.1
 - v1.1.0
 - 1.0.x-dev
 - v1.0.9.1
 - v1.0.9
 - v1.0.8
 - v1.0.7
 - v1.0.6
 - v1.0.5
 - v1.0.4
 - v1.0.3
 - v1.0.2
 - v1.0.1
 - v1.0.0
 - dev-dependabot/github_actions/actions/upload-artifact-5
 - dev-dependabot/github_actions/actions/checkout-5
 - dev-dependabot-phpunit-12
 - dev-dependabot-codecov-v5
 
This package is auto-updated.
Last update: 2025-10-27 15:25:07 UTC
README
A modern logging factory library based on Monolog, designed for PHP 8.3+, providing powerful logging management capabilities and seamless Laravel framework integration.
π§ͺ High Quality Assurance: Features 88.82% test coverage with 144 test methods and 367 assertions, ensuring code quality and stability.
π Stable Release: Current version is 2.0.0, a stable release ready for production use. This version has been thoroughly tested with 87.28% test coverage and enterprise-grade quality assurance.
π€ AI-Driven Development: This project's refactoring and testing improvements were completed entirely by Augment intelligent coding AI tool, demonstrating AI's powerful capabilities in modern software development.
π Table of Contents
- β¨ Key Features
 - π System Requirements
 - π Installation
 - π Usage
 - π§ Laravel Integration
 - π§ͺ Testing
 - β οΈ Version Notes
 - π€ Contributing
 - π Support
 - π License
 - π Acknowledgments
 
β¨ Key Features
π Modern PHP 8.3+ Features
- Strict Type Declarations: Comprehensive use of 
declare(strict_types=1)and typed properties - Constructor Property Promotion: Concise constructor syntax
 - Readonly Properties: Using 
readonlykeyword to protect important properties - Match Expressions: Replacing traditional switch statements with safer pattern matching
 - Union Types: Support for flexible type definitions like 
int|Level|string 
π― Core Functionality
- Multi-Channel Log Management: Support for separating log channels by functional modules
 - Rich Processors: Built-in performance profiling, memory monitoring, web request processors
 - Flexible Formatting: Support for JSON, HTML, custom formats and multiple output formats
 - Smart Rotation: Automatic log file rotation by date and file size
 - Exception Enhancement: Automatic extraction and structured recording of detailed exception information
 - Filter Support: Custom log filtering logic
 
π§ Laravel Integration
- Zero Configuration: Automatic service discovery and registration
 - Facade Support: 
MLogfacade for convenient access - Helper Functions: 
mlog(),mlog_with(),mlog_debug()etc. - Middleware Support: Built-in request logging middleware
 - Artisan Commands: Testing and management commands
 - Configuration Publishing: Customizable configuration files
 
π Advanced Features
- Performance Monitoring: Built-in execution time and memory usage tracking
 - Context Enhancement: Automatic addition of request ID, user information, etc.
 - Error Handling: Graceful handling of logging failures
 - Caching Support: Intelligent caching for improved performance
 - Security Features: Sensitive data filtering and sanitization
 
π System Requirements
- PHP: 8.3 or higher
 - Monolog: ^3.0
 - PSR-Log: ^3.0
 - Laravel: ^10.0 | ^11.0 (optional, for Laravel integration)
 
Installation
Install the stable version using Composer:
# Install stable version composer require mellivora/logger-factory:^2.0.0 # Or specify exact version composer require mellivora/logger-factory:2.0.0
Usage
Basic Usage
<?php use Mellivora\Logger\LoggerFactory; use Monolog\Level; // Create factory instance $factory = new LoggerFactory(); // Get default logger $logger = $factory->get(); $logger->info('Hello World!'); // Use specific channel $apiLogger = $factory->get('api'); $apiLogger->debug('API request processed');
Laravel Integration
<?php // Using helper functions mlog('info', 'User logged in', ['user_id' => 123]); mlog_with('api', 'debug', 'API request'); // Using Facade use Mellivora\Logger\Laravel\Facades\MLog; MLog::info('Application started'); MLog::logWith('api', 'debug', 'API debug'); MLog::exception($exception, 'error');
For complete Laravel integration guide, see Laravel Documentation.
Advanced Configuration
<?php use Mellivora\Logger\LoggerFactory; use Mellivora\Logger\Config\LoggerConfig; // Custom configuration $config = new LoggerConfig([ 'default_channel' => 'app', 'channels' => [ 'app' => [ 'handlers' => [ [ 'type' => 'rotating_file', 'path' => '/var/log/app.log', 'level' => 'info', 'max_files' => 30, ], ], ], ], ]); $factory = new LoggerFactory($config); $logger = $factory->get('app');
π§ Laravel Integration
Installation
- Install the package:
 
composer require mellivora/logger-factory:^2.0.0
- Publish configuration (optional):
 
php artisan vendor:publish --provider="Mellivora\Logger\Laravel\MellivoraLoggerServiceProvider"
Configuration
Edit config/mellivora-logger.php:
<?php return [ 'default_channel' => env('MELLIVORA_LOG_CHANNEL', 'default'), 'channels' => [ 'default' => [ 'handlers' => [ [ 'type' => 'rotating_file', 'path' => storage_path('logs/mellivora.log'), 'level' => env('MELLIVORA_LOG_LEVEL', 'debug'), 'max_files' => 30, ], ], ], 'api' => [ 'handlers' => [ [ 'type' => 'rotating_file', 'path' => storage_path('logs/api.log'), 'level' => 'info', 'max_files' => 30, ], ], ], ], ];
Usage Examples
<?php // Helper functions mlog('info', 'User action', ['action' => 'login', 'user_id' => 123]); mlog_with('api', 'debug', 'API request', ['endpoint' => '/users']); // Facade use Mellivora\Logger\Laravel\Facades\MLog; MLog::info('Application started'); MLog::error('Database connection failed', ['error' => $exception->getMessage()]); // Exception logging try { // Some operation } catch (Exception $e) { MLog::exception($e, 'error', 'payment'); }
π§ͺ Testing
Running Tests
# Run all tests composer test # Run tests with coverage composer test:coverage # Run specific test suite ./vendor/bin/phpunit tests/LoggerFactoryTest.php
Test Coverage
Current test coverage: 88.82%
- Total Tests: 144
 - Assertions: 367
 - Files Covered: 30
 - Lines Covered: 1,234 / 1,389
 
For detailed testing information, see Testing Documentation.
β οΈ Version Notes
Alpha Version (2.0.0-alpha)
This is a pre-release version with the following characteristics:
β Completed Features
- Core Functionality: All core features implemented and tested
 - High Quality: 88.82% test coverage ensuring code quality
 - Complete Documentation: Comprehensive usage documentation and examples
 - Production Ready: Although alpha, quality meets production standards
 
π― Usage Recommendations
- New Projects: Recommended for use, feature-complete and stable
 - Testing Environment: Suitable for evaluation and validation in test environments
 - Production Environment: Recommended to conduct thorough testing before production deployment
 - Legacy Versions: Not recommended to upgrade from legacy versions due to significant architectural differences
 
Breaking Changes from 1.x
- PHP Version: Minimum requirement upgraded to PHP 8.3+
 - Function Names: Simplified from 
mellivora_log()tomlog() - Facade Name: Changed from 
MellivoraLoggertoMLog - Architecture: Complete rewrite with modern PHP features
 - Dependencies: Updated to Monolog 3.x and modern packages
 
π€ Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository git clone https://github.com/zhouyl/mellivora-logger-factory.git cd mellivora-logger-factory # Install dependencies composer install # Run tests composer test # Check code style composer cs-check # Fix code style composer cs-fix
π Support
- Documentation: Complete Documentation
 - Issues: GitHub Issues
 - Discussions: GitHub Discussions
 
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Monolog: The excellent logging library that powers this factory
 - Laravel: For the outstanding framework integration support
 - Symfony: For the powerful component ecosystem
 - PHPUnit: For the reliable testing framework
 - Augment: For the AI-powered development tools that made this project possible
 
Made with β€οΈ and AI assistance