Download the PHP package dschuppelius/php-error-toolkit without Composer
On this page you can find all versions of the php package dschuppelius/php-error-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dschuppelius/php-error-toolkit
More information about dschuppelius/php-error-toolkit
Files in dschuppelius/php-error-toolkit
Package php-error-toolkit
Short Description Logging and error handling foundation for the Schuppelius PHP toolkits (PSR-3 loggers, global error handler, LoggerRegistry, Laravel bridge)
License MIT
Informations about the package php-error-toolkit
PHP Error Toolkit
A PSR-3 compliant logging library built for PHP 8.1+ with a focus on console and file logging. Designed as a lightweight, reusable component for modern PHP applications.
Features
- 🎯 PSR-3 Compliant - Full compatibility with PSR-3 logging standards
- 🖥️ Console Logging - Colored output with ANSI support and terminal detection
- 📄 File Logging - Automatic log rotation and fail-safe mechanisms
- 🏭 Factory Pattern - Clean instantiation with singleton behavior
- 🌐 Global Registry - Centralized logger management across your application
- ✨ Magic Methods - Convenient
logDebug(),logInfo(),logErrorAndThrow()methods via trait - ⏱️ Timer Logging - Measure execution time with
logInfoWithTimer()and similar methods - 🔄 Conditional Logging -
logInfoIf(),logErrorUnless()for conditional log output - 🔧 OS Helper - Cross-platform system detection and utilities
- 🎨 Cross-Platform - Windows, Linux and macOS terminal support
- 🧪 Fully Tested - Comprehensive test suite with PHPUnit
Installation
Install via Composer:
Requirements
- PHP 8.1 to 8.4
- PSR-3 Log Interface
Quick Start
Basic Usage with Console Logger
File Logging
Using the ErrorLog Trait
Add logging capabilities to any class:
Logger Types
Console Logger
- Colored output with level-specific colors
- Automatic terminal detection
- Debug console support (VS Code, etc.)
- Clean formatting with newline management
File Logger
- Automatic log rotation when size limit exceeded
- Fail-safe fallback to console/syslog
- Customizable file size limits
- Thread-safe file operations
Null Logger
- Silent logger for testing/production environments
- PSR-3 compliant no-op implementation
Global Logger Registry
Manage loggers globally across your application:
Log Levels
Supports all PSR-3 log levels with integer-based filtering:
EMERGENCY(0) - System is unusableALERT(1) - Action must be taken immediatelyCRITICAL(2) - Critical conditionsERROR(3) - Error conditionsWARNING(4) - Warning conditionsNOTICE(5) - Normal but significant conditionINFO(6) - Informational messagesDEBUG(7) - Debug-level messages
ErrorLog Trait Features
The ErrorLog trait provides comprehensive logging capabilities with multiple advanced features:
Magic Methods
All PSR-3 log levels are available as magic methods:
Hex Output for String Messages
For debugging encoding or binary transport issues, you can log a message with an additional hex representation:
Jedes Zeichen steht genau über seinem Hex-Code. Für Multibyte-Zeichen (z. B. ä → C3 A4) wird die Zeichenspalte entsprechend verbreitert:
You can also enable it on direct PSR-3 logger calls via context flag:
Conditional Logging
Log messages only when conditions are met:
Log with Timer
Measure execution time of operations:
Log and Return
Log a message and return a value in one call:
Log Exceptions
Log exceptions with full stack trace:
Log and Throw Exceptions
Combine logging and exception throwing in a single call with log{Level}AndThrow():
Available log-and-throw methods:
| Method | Log Level |
|---|---|
logErrorAndThrow() |
ERROR |
logCriticalAndThrow() |
CRITICAL |
logAlertAndThrow() |
ALERT |
logEmergencyAndThrow() |
EMERGENCY |
Method signature:
Logger Management
The trait provides flexible logger management:
Automatic Project Detection
The trait automatically detects project names from class namespaces:
Fallback Logging System
When no logger is available, the trait provides intelligent fallbacks:
- Primary: Uses configured PSR-3 logger
- Fallback 1: PHP error_log() if configured
- Fallback 2: System syslog with project-specific facility
- Fallback 3: File logging to system temp directory
Context Support
All logging methods support PSR-3 context arrays:
Configuration
Log Level Filtering
File Logger Options
Testing
Run the test suite:
Or run PHPUnit directly:
Cross-Platform Terminal Support
The toolkit automatically detects:
- Windows VT100 support via
sapi_windows_vt100_support() - Unix/Linux TTY via
posix_isatty() - Debug consoles (VS Code, PHPStorm, etc.)
- PHPUnit color configuration
Helper Classes
OsHelper
Cross-platform operating system detection and utilities:
TerminalHelper
Terminal detection and capabilities:
PhpUnitHelper
PHPUnit-specific utilities:
Architecture
- Factory Pattern - All loggers created via factories with singleton behavior
- Strategy Pattern - Different logging strategies (Console, File, Null)
- Registry Pattern - Global logger management
- Trait-based - Easy integration via
ErrorLogtrait - Helper Classes - Reusable utilities for OS detection, terminal handling, PHPUnit support
- PSR-3 Compliant - Standard logging interface
License
MIT License. See LICENSE file for details.
Author
Daniel Jörg Schuppelius
- Website: schuppelius.org
- Email: [email protected]
Contributing
This is a personal toolkit for Daniel Schuppelius's projects. For bugs or feature requests, please open an issue.