Download the PHP package timdev/stack-logger without Composer
On this page you can find all versions of the php package timdev/stack-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package stack-logger
PHP Stack Logger
Wrap your PSR-3 logger with context accumulation and callable context elements.
Inspiration
Inspired by the similar functionality in pinojs. Design and implementation details differ, but the core idea remains:
Approach
The provided implementation decorates any
implementation of the PSR3 LoggerInterface, providing implementation of the
additional withContext
and addContext
methods defined in this library's
StackLogger interface.
Also provided is MonologStackLogger
, which
decorates a Monolog\Logger
and provides a working withName
implementation.
Usage
Context Stacking
This can be useful in any situation where want to carry some context through successive calls.
Dynamic (Callable) Context
The other feature provided here is callable context. Any context elements that
are callable
will be invoked at logging-time, and the result of the
computation will be logged. Callables take a single array argument:
function(array $context): mixed
NOTE: you should carefully consider the performance implications when using callables in your stacked context. Context is processed before invoking the wrapped logger's methods. The callables will be invoked on every logging method call, even if the underlying logger is configured to ignore the log-level.
NullLoggers
All StackLogger
implementations provide a static getNullLogger()
method,
which returns an instance that is configured to discard all log messages. These
"null loggers" can be handy in tests, or as a default logger in classes that
can optionally accept a real logger:
To Do
- [ ] Make MonologStackLogger implement Monolog's ResettableInterface?
- [ ] Consider how this might play with Laravel, the insanely popular PHP framework that I do my best to avoid. 😜
- [ ] Track what's going on with PSR-3 v2/v3 as well as monolog and
laminas-log. Eventually, we should rely on the updated + better-typed
versions of the spec. We may need to drop the laminas-log test code since laminas-log will likely always require psr/[email protected]