Download the PHP package vaibhavpandeyvpz/drishti without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/drishti. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/drishti
More information about vaibhavpandeyvpz/drishti
Files in vaibhavpandeyvpz/drishti
Package drishti
Short Description A lightweight, flexible PSR-3 compliant logging library with configurable backends and zero dependencies.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/drishti
Informations about the package drishti
Drishti
A lightweight, flexible PSR-3 compliant logging library with configurable backends, PSR-20 Clock support, and minimal dependencies.
Drishti (
दृष्टि) - Sanskrit for "Vision" or "Sight", representing the ability to see and record what happens in your application.
Features
- ✅ PSR-3 Compliant - Full implementation of the PSR-3 LoggerInterface specification
- ✅ PSR-20 Clock Support - Uses PSR-20 ClockInterface for time operations (testable and flexible)
- ✅ Minimal Dependencies - Only requires PSR-3 interface (psr/log) and PSR-20 Clock (psr/clock)
- ✅ Configurable Backends - Contract-based backend system for flexible log destinations
- ✅ Multiple Backends - Send logs to multiple destinations simultaneously
- ✅ First-Party Backends - Built-in support for stdout, stderr, files, and daily rotating files
- ✅ First-Party Formatters - Built-in SimpleLogEntryFormatter and JsonLogEntryFormatter
- ✅ Message Interpolation - Automatic placeholder replacement with context data
- ✅ Exception Handling - Automatic exception information in log entries
- ✅ All Log Levels - Supports all 8 PSR-3 log levels
- ✅ Modern PHP - Built for PHP 8.2+ with modern language features
- ✅ 100% Test Coverage - Fully tested with comprehensive test suite
Installation
Install via Composer:
Quick Start
Usage
Basic Logging
The Logger class implements the PSR-3 LoggerInterface and provides methods for all standard log levels:
Message Interpolation
Drishti supports PSR-3 message interpolation using placeholders in the form {key}:
Context Data Types
The logger handles various context data types:
Exception Logging
When an exception is included in the context with the key exception, Drishti automatically appends exception details:
Using the log() Method
You can also use the generic log() method with any valid PSR-3 log level:
Stringable Messages
Messages can be strings or objects implementing \Stringable:
Backend System
Drishti uses a contract-based backend system that allows you to configure where logs are written. You can use one or more backends simultaneously.
Default Behavior
If no backends are configured, Drishti uses default behavior:
- Error levels (emergency, alert, critical, error): Written to
STDERR - Informational levels (warning, notice, info, debug): Written to
STDOUT
Using Backends
Configure backends when creating the logger:
Available Backends
StdioBackend
Writes logs to standard I/O streams (STDOUT or STDERR). Use static factory methods to create instances:
FileBackend
Writes logs to a single file. The directory will be created automatically if it doesn't exist:
DailyFileBackend
Writes logs to daily rotating files (logrotate style). Files are named with the date suffix:
Custom Backends
Create your own backend by implementing BackendInterface:
Multiple Backends
Send logs to multiple destinations simultaneously:
Formatters
Drishti includes two first-party formatters and supports custom formatters.
SimpleLogEntryFormatter (Default)
The default formatter produces human-readable log entries:
Output format: [2024-01-15 10:30:45] INFO: User logged in
JsonLogEntryFormatter
For structured logging, use the JSON formatter:
Output format:
The JSON formatter includes:
- ISO 8601 timestamp
- Uppercased log level
- Interpolated message
- Exception details (if present)
- Remaining context data
Custom Formatters
You can create custom formatters by implementing LogEntryFormatterInterface:
PSR-20 Clock Support
Drishti uses PSR-20 ClockInterface for all time operations, making it testable and flexible. All backends and formatters accept an optional ClockInterface instance.
For testing, you can use a frozen clock like samay:
Output Format
All log entries include a timestamp in the format [YYYY-MM-DD HH:MM:SS].
Example output:
Requirements
- PHP 8.2 or higher
- PSR-3 interface (psr/log)
- PSR-20 Clock interface (psr/clock)
For testing, we recommend samay for frozen clocks:
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues, questions, or contributions, please visit the GitHub repository.