A lightweight, production-ready logging utility for development environments.
- PHP 7.4 or higher
- Composer (recommended for installation)
- Features
- Installation
- Usage
- Log Levels
- Log Format
- File Structure
- Configuration
- Testing
- Contributing
- License
- Security
- Multiple log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Automatic log rotation (10MB max, keeps 5 files)
- Context data support
- Thread-safe file writing
- Git-ignored log files
- PSR-4 autoloading
- Composer package support
- Comprehensive test suite
- GitHub Actions CI/CD
composer require jmrashed/loggerDownload the Logger.php file and include it in your project.
// Using Composer autoload
require_once 'vendor/autoload.php';
// Or manual include
require_once $_SERVER['DOCUMENT_ROOT'] . '/_Logger/Logger.php';
// Basic logging
\DevLogger\Logger::info('User logged in');
\DevLogger\Logger::error('Database connection failed');
\DevLogger\Logger::warning('Deprecated function used');
// Logging with context
\DevLogger\Logger::info('User action', ['user_id' => 123, 'action' => 'login']);
\DevLogger\Logger::error('Query failed', ['query' => 'SELECT * FROM users', 'error' => $e->getMessage()]);DEBUG- Detailed debug informationINFO- General information messagesWARNING- Warning messagesERROR- Error conditionsCRITICAL- Critical conditions
[2024-01-15 14:30:25] [INFO] User logged in {"user_id":123,"action":"login"}
_Logger/
├── Logger.php # Main logger class
├── example.php # Usage example
├── composer.json # Composer package configuration
├── phpunit.xml.dist # PHPUnit configuration
├── .gitignore # Git ignore rules
├── CHANGELOG.md # Change log
├── CODE_OF_CONDUCT.md # Code of conduct
├── CONTRIBUTING.md # Contributing guidelines
├── LICENSE # License file
├── README.md # This file
├── SECURITY.md # Security policy
├── .github/ # GitHub workflows and templates
├── docs/ # Documentation
│ ├── API.md # API documentation
│ └── INSTALL.md # Installation guide
└── tests/ # Test files
└── LoggerTest.php # Unit tests
The logger automatically:
- Creates log directory if it doesn't exist
- Rotates logs when they exceed 10MB
- Keeps maximum 5 log files
- Uses thread-safe file writing
Run the test suite:
composer testContributions are welcome! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
For security issues, please see our Security Policy.
Md Rasheduzzzaman
- Email: jmrashed@gmail.com
- GitHub: @jmrashed
- Repository: https://github.com/jmrashed/logger