mellivora/logger-factory
Composer 安装命令:
composer require mellivora/logger-factory
包简介
A modern logger factory library based on Monolog for PHP 8.3+, with seamless Laravel integration
README 文档
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
统计信息
- 总下载量: 481
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-17