jidaikobo/log
is a simple and flexible logging utility that adheres to the PSR-3 (Logger Interface) standard. It provides both instance-based and static methods for logging, making it easy to integrate into any PHP project.
This package was developed to simplify logging in small-scale projects, such as those using the Slim Framework. It also fulfills the need to log arrays efficiently, which can be crucial for debugging.
- PSR-3 compliant: Supports all standard logging levels.
- Instance-based design: Fully compatible with dependency injection and modern PHP practices.
- Static wrapper: Offers convenient static methods for quick and simple logging.
- Log file rotation: Automatically rotates log files when they reach a specified size.
- Error and exception handling: Integrates with PHP error and exception handling mechanisms.
Install the package via Composer:
composer require jidaikobo/log
Initialize the logger with a custom log file path and maximum file size (optional):
use Jidaikobo\Log;
Log::init('/path/to/log.log', 5 * 1024 * 1024); // 5MB max file size
If Log::init() is not explicitly called, the logger will use default settings.
Log messages at various levels using static methods:
Log::info('This is an informational message.');
Log::warning('This is a warning message.');
Log::error('An error occurred.');
Log::debug('Debugging details.');
To output an array:
Log::write(['foo', 'bar', 'baz']);
Register the logger to handle PHP errors and uncaught exceptions:
Log::getInstance()->registerHandlers();
- PHP >= 7.4
This project is licensed under the MIT License, see the LICENSE file for details