Download the PHP package meritum/structured-logging without Composer
On this page you can find all versions of the php package meritum/structured-logging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download meritum/structured-logging
More information about meritum/structured-logging
Files in meritum/structured-logging
Package structured-logging
Short Description Meritum module for structured exception logging — domain exception model, translation pipeline, PSR-3 reporting, and correlation ID enrichment
License MIT
Informations about the package structured-logging
meritum/structured-logging
Structured exception logging for the Meritum ecosystem. Provides a domain exception model, a translation pipeline that converts arbitrary exceptions into structured domain exceptions, PSR-3 reporting, and correlation ID enrichment.
Installation
A PSR-3 logger must be registered in your kernel before adding this module. meritum/logger is a zero-dependency option.
Module registration
The module registers the following services:
| Service | Notes |
|---|---|
CorrelationId |
Singleton. Auto-generates a UUID v4 on first resolution. |
CorrelationIdEnricher |
Tagged as log.context.enrichers. Adds correlation_id to every log entry. |
ExceptionTranslator |
Collects all exception.translator.handlers tagged services. |
ExceptionReporter |
Translates, then logs via the decorated LoggerInterface. |
LoggerInterface |
Decorated with ContextEnrichingLogger to apply registered enrichers. |
Domain exceptions
Define your own domain exceptions by extending DomainException:
Every domain exception exposes a structuredData property containing the full structured payload, which lands in the PSR-3 log context:
The detail key carries the per-exception contextual data passed in $context. This is deliberately named to avoid a collision with the PSR-3 context array wrapper that some loggers produce.
Translation pipeline
The translator converts arbitrary Throwable instances into domain exceptions. Handlers are registered as tagged kernel services — the translator collects them automatically at boot.
Defining a handler
Implement TranslationHandler and tag it as exception.translator.handlers in your module:
Higher priority() values win when multiple handlers match the same exception. If no handler matches, the translator wraps the exception in an UnknownException and logs it at error severity.
Using the translator directly
If $e is already a DomainException, it is returned as-is.
Reporting
ExceptionReporter::report() runs the full pipeline — translate, enrich, log — and returns the resulting DomainException for the caller to act on (render a response, rethrow, etc.):
Context enrichment
Enrichers add data to the PSR-3 log context on every log call through the decorated logger. CorrelationIdEnricher is registered automatically. Add your own by implementing ContextEnricher and tagging it:
Use the + operator rather than array_merge so that context values already set by the caller are not overwritten.
Correlation ID
CorrelationId is a singleton auto-generated at boot. It is automatically added to every log entry via CorrelationIdEnricher.
To overwrite the generated ID from an incoming HTTP request header (e.g. in a PSR-15 middleware):
set() validates the value as a UUID v4. Invalid or missing values are silently ignored and the auto-generated ID is preserved — a garbage header from a client is not an exceptional condition.
Severity levels
| Case | PSR-3 level |
|---|---|
Severity::Critical |
critical |
Severity::Error |
error |
Severity::Warning |
warning |
Severity::Info |
info |
Severity::Debug |
debug |