Download the PHP package antlerops/error-logger without Composer
On this page you can find all versions of the php package antlerops/error-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download antlerops/error-logger
More information about antlerops/error-logger
Files in antlerops/error-logger
Package error-logger
Short Description Advanced error logger with multiple transport options and rate limiting
License MIT
Informations about the package error-logger
Antler Error Logger
An advanced PHP error logging system with comprehensive context capture, multiple transport options, and robust error handling for PHP 7.1+ and PHP 8.0+ applications.
Features
- Multi-Transport Logging: Log to remote endpoints, local files, and PHP error log simultaneously
- Enhanced Stack Traces: Captures source code context around errors with line numbers
- Intelligent Environment Detection: Automatically captures different context in CLI vs. web environments
- Rich Context: Captures system state, execution performance, HTTP request details, and more
- Privacy-Aware: Automatically sanitizes sensitive data (passwords, tokens, etc.)
- Rate Limiting: Prevents log flooding during high-volume error situations
- Performance Monitoring: Tracks memory usage and execution time for errors
- Simple Integration: Drop-in error handling with minimal configuration
- Container-Aware: Detects containerized environments
- Contextual Tagging: Tag logs for better categorization and filtering
- Request Tracking: Correlate logs from the same request with request IDs
- Performance Instrumentation: Built-in timers for measuring code execution time
- Nested Context: Maintain hierarchical context through code execution
- Sampling: Control log volume with configurable sampling rates
- Circuit Breaker: Prevent log flooding during error cascades
- Log Filtering: Filter logs based on message patterns or context values
- Asynchronous Processing: Non-blocking log processing for better performance
Installation
Basic Usage
Configuration Options
Config Key | Default Value | Description |
---|---|---|
project_hash |
null |
Required: Unique project identifier |
remote_endpoint |
null |
Remote logging API URL (Required for remote logging) |
log_file_path |
./logs/application.log |
Path to local log file |
request_timeout |
2 |
Timeout in seconds for remote requests |
min_log_level |
LogLevel::WARNING |
Minimum severity level to log (DEBUG to CRITICAL) |
use_remote_logging |
true |
Enable/disable remote logging |
use_file_logging |
true |
Enable/disable local file logging |
use_error_log |
true |
Use PHP error_log() for ERROR+ levels |
rate_limit_per_minute |
60 |
Maximum allowed logs per minute to prevent flooding |
sampling_rate |
1.0 |
Sampling rate for logs (0.0 to 1.0) |
circuit_breaker_threshold |
0 |
Errors per minute to trigger circuit breaker (0=disabled) |
circuit_breaker_cooldown |
60 |
Seconds to keep circuit breaker open |
async_processing |
false |
Send logs asynchronously (non-blocking) |
Environment Variables
All configuration options can be set via environment variables:
Configuration in code overrides environment variables.
Enhanced Stack Traces with Code Context
One of the powerful features of Antler Error Logger is the ability to capture detailed code context around errors. This makes debugging easier by showing you exactly what was happening in your code when the error occurred:
This will include the enhanced stack trace with source code context in your logs.
Log Levels
The logger offers five standard severity levels:
Contextual Tagging
Tags allow you to categorize log entries for easier filtering and analysis.
Log Entry and Request Tracking
Each log entry now includes a unique ID, and logs from the same request are linked with a request ID:
Performance Instrumentation
Track execution time and memory usage:
Nested Context Support
Maintain a context stack throughout code execution:
Sampling and Circuit Breaker
Reduce log volume in high-traffic scenarios:
Log Filtering
Filter out unwanted log entries:
Asynchronous Processing
Process logs without blocking application execution:
Automatic Context Capture
The logger automatically captures different information depending on the execution environment:
Common to Both CLI and Web
- Project identifier
- PHP version and SAPI
- Memory usage, peak, and growth since logger initialization
- Memory limit
- Execution time
- Maximum execution time
- Operating system
- Timezone
- Server hostname
- Process ID
- Container detection
CLI-Specific Context
- Script arguments (argc/argv)
- Script filename
- Current working directory
- Current user
Web-Specific Context
- Full URL and components (scheme, host, path)
- HTTP method
- Query parameters (sanitized)
- Client IP address
- User agent
- Referrer
- HTTP headers
- Request body (JSON or form data, sanitized)
- Session information (when available)
Data Privacy and Sanitization
The logger automatically redacts sensitive information from request data. Fields containing the following strings will be redacted:
- password, passwd
- secret, token, auth
- key, apikey, api_key
- access_token, accesstoken
- credential, private
- ssn, social_security
- cc, card, credit, cvv, cvc
For example:
Remote Payload Example
Here's an example of what the logger sends to remote endpoints, including the enhanced stack trace:
Advanced Configuration Examples
Development Environment
High-Traffic Production Environment
CLI Application Example
Laravel Integration
Antler Error Logger integrates easily with Laravel applications thanks to its singleton pattern. This section covers how to use the error logger directly in Laravel without additional facades or service providers.
Supported Laravel Versions
Antler Error Logger is compatible with the following Laravel versions:
Laravel Version | PHP Compatibility | Support Status |
---|---|---|
Laravel 6.x | PHP 7.2 or higher | ✓ Supported |
Laravel 7.x | PHP 7.2.5 or higher | ✓ Supported |
Laravel 8.x | PHP 7.3 or higher | ✓ Supported |
Laravel 9.x | PHP 8.0.2 or higher | ✓ Supported |
Laravel 10.x | PHP 8.1 or higher | ✓ Supported |
Laravel 11.x | PHP 8.2 or higher | ✓ Supported |
Laravel 12.x | PHP 8.2 or higher | ✓ Supported |
Note: For PHP 7.1 compatibility, you must use Laravel 5.8 or earlier. Laravel 6.0+ requires PHP 7.2+.
Simple Installation
-
Install the package via Composer:
- That's it! No service providers or facades required.
Basic Usage in Laravel
Since the Antler Error Logger uses a singleton pattern, you can access it directly in your Laravel application:
Recommended Setup in Laravel
Bootstrap Integration
A clean way to integrate the logger is by initializing it in a service provider. You can use Laravel's AppServiceProvider
or create a dedicated provider:
Then register this provider in your config/app.php
:
Integrating with Laravel's Exception Handler
To capture all exceptions in your Laravel application, you can modify your exception handler:
Troubleshooting
Remote Logging Not Working
-
Check connectivity to your remote endpoint:
-
Verify your PHP installation has required extensions:
- Check for PHP warnings in your error log about cURL or stream requests.
File Logging Issues
-
Check directory permissions:
- Create the log directory manually and set proper permissions:
PHP Error Handler Integration
The logger automatically registers handlers for:
- Uncaught exceptions (via
set_exception_handler
) - PHP errors (via
set_error_handler
) - Fatal errors (via
register_shutdown_function
)
These handlers capture detailed information about errors, including the enhanced stack traces with code context, and send them through all configured transports.
Remote Payload Changes
The logger now includes the following additional fields in the remote payload:
These additions are backward compatible with existing remote endpoints, as they only add new fields without modifying or removing existing ones.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Requirements
- PHP 7.1 or higher
- For remote logging: Either cURL extension or
allow_url_fopen
enabled
All versions of error-logger with dependencies
ext-curl Version *
ext-json Version *