Download the PHP package kevinpirnie/kpt-logger without Composer
On this page you can find all versions of the php package kevinpirnie/kpt-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download kevinpirnie/kpt-logger
More information about kevinpirnie/kpt-logger
Files in kevinpirnie/kpt-logger
Download kevinpirnie/kpt-logger
More information about kevinpirnie/kpt-logger
Files in kevinpirnie/kpt-logger
Vendor kevinpirnie
Package kpt-logger
Short Description Simple Universal Application Logger for PHP with configurable output destinations and four standard log levels
License MIT
Homepage https://github.com/kpirnie/kpt-logger
Package kpt-logger
Short Description Simple Universal Application Logger for PHP with configurable output destinations and four standard log levels
License MIT
Homepage https://github.com/kpirnie/kpt-logger
Please rate this library. Is it a good library?
Informations about the package kpt-logger
KPT Logger
A simple, universal application logger for PHP that provides basic logging capabilities with configurable output destinations and four standard log levels.
Features
- Four Log Levels: ERROR, WARNING, INFO, DEBUG
- Flexible Output: Log to system log or custom file
- Context Support: Include additional data with log entries
- Stack Traces: Optional stack trace inclusion for debugging
- Always-On Errors: Error messages log even when logging is disabled
- Thread-Safe: File writing with exclusive locks
- Easy Integration: Simple static methods for quick logging
Requirements
- PHP 8.0 or higher
- Write permissions for log file directory (if using file logging)
Installation
Install via Composer:
Basic Usage
Initialize the Logger
Log Messages
Using the Alias
Configuration
Set Log File
Advanced Logging with Context
Log Levels
| Level | Constant | Description | Always Logs |
|---|---|---|---|
| ERROR | Logger::LEVEL_ERROR |
Error conditions | ✅ Yes |
| WARNING | Logger::LEVEL_WARNING |
Warning conditions | Only when enabled |
| INFO | Logger::LEVEL_INFO |
Informational messages | Only when enabled |
| DEBUG | Logger::LEVEL_DEBUG |
Debug-level messages | Only when enabled |
Output Format
Log entries are formatted as follows:
Format breakdown:
[2024-08-18 14:30:25]- TimestampERROR- Log levelDatabase connection failed- Your messageContext: {...}- Additional context data (if provided)Stack: [...]- Stack trace (if enabled)
Examples
Basic Error Logging
Application Monitoring
API Integration Logging
File Logging Setup
Best Practices
- Initialize Early: Set up the logger at the beginning of your application
- Use Appropriate Levels: Reserve ERROR for actual errors, use DEBUG sparingly in production
- Include Context: Add relevant data to help with debugging
- Handle File Permissions: Ensure your application can write to the log directory
- Log File Rotation: Implement log rotation for production environments
- Sensitive Data: Avoid logging passwords or other sensitive information
Thread Safety
The logger uses LOCK_EX when writing to files, making it safe for concurrent access in multi-threaded environments.
Performance Considerations
- Disabled logging levels have minimal performance impact (simple boolean check)
- Stack traces add overhead - disable in production if not needed
- File I/O is synchronous - consider async logging for high-traffic applications
Author
Kevin Pirnie - [email protected]
License
Part of the KP Library package.
Version
Since version 8.4
All versions of kpt-logger with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.4
The package kevinpirnie/kpt-logger contains the following files
Loading the files please wait ...