Download the PHP package tiny-blocks/logger without Composer
On this page you can find all versions of the php package tiny-blocks/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tiny-blocks/logger
More information about tiny-blocks/logger
Files in tiny-blocks/logger
Package logger
Short Description Emits PSR-3 structured logs for PHP, with correlation tracking and configurable sensitive data redaction.
License MIT
Homepage https://github.com/tiny-blocks/logger
Informations about the package logger
Logger
- Overview
- Installation
- How to use
- Basic logging
- Correlation tracking
- Sensitive data redaction
- Custom log template
- License
- Contributing
Overview
Emits PSR-3 structured logs for PHP, with each entry carrying timestamp, component, correlation id, level, and a structured data payload. Supports pluggable redactions for sensitive fields such as passwords, emails, phone numbers, and identity documents. Built for consumption by log aggregators and SIEM pipelines in production environments.
Installation
How to use
Basic logging
Create a logger with StructuredLogger::create() and use the fluent builder to configure it. All PSR-3 log levels are
supported: debug, info, notice, warning, error, critical, alert, and emergency.
Output (default template, written to STDERR):
Correlation tracking
A correlation ID can be attached at creation time or derived later using withContext. The original instance is never
mutated.
At creation time
Derived from an existing logger
Sensitive data redaction
Redaction is optional and configurable. Built-in redaction strategies are provided for common sensitive fields. Each strategy accepts multiple field name variations and a configurable masking length.
Document redaction
Masks all characters except the last N (default: 3).
With custom fields and visible length:
Email redaction
Preserves the first N characters of the local part (default: 2) and the full domain.
With custom fields:
Phone redaction
Masks all characters except the last N (default: 4).
With custom fields:
Password redaction
Masks the entire value with a fixed-length mask (default: 8 characters). The original value's length is never revealed in the output, preventing information leakage about password size.
With custom fields and fixed mask length:
Name redaction
Preserves the first N characters (default: 2) and masks the rest.
With custom fields and visible length:
Composing multiple redactions
Custom redaction
Implement the Redaction interface to create your own strategy:
Then add it to the logger:
Custom log template
The default output template is:
You can replace it with any sprintf compatible template that accepts six string arguments (timestamp, component,
correlationId, level, key, data):
License
Logger is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.