Download the PHP package helsingborg-stad/psr-logger without Composer
On this page you can find all versions of the php package helsingborg-stad/psr-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download helsingborg-stad/psr-logger
More information about helsingborg-stad/psr-logger
Files in helsingborg-stad/psr-logger
Package psr-logger
Short Description Implementation of PSR-3: Logger Interface.
License MIT
Informations about the package psr-logger
PSR Logger
A PSR-3 compatible logger factory with namespace breadcrumbs, log-level filtering, and context placeholder interpolation. See the full PSR-3 specification for the interface contract this library implements.
Requirements
- PHP 8.2 or higher
psr/log^2.0 || ^3.0
Installation
With composer:
Basic usage
Child loggers (namespace tree)
createLogger() returns a LoggerInterface & LoggerFactoryInterface, so you can branch the namespace tree by calling createLogger(['namespace' => '...']) on any logger.
Namespace display defaults to breadcrumbMaxCount: -1 — all segments are shown. Set breadcrumbMaxCount to a positive integer to limit how many are displayed (e.g. 2 shows only the first and last segment).
Context placeholders
{key} tokens in the message are replaced with matching values from the $context array.
- Valid key characters are
A-Za-z0-9_.— hyphens, whitespace, or other characters leave the token unreplaced - No whitespace inside braces:
{ name }is never interpolated - Dot notation resolves nested arrays (
user.name→$context['user']['name']) - A flat key (
'user.name') takes precedence over dot-notation traversal when both exist in context - Scalars (
int,float) are cast to string;Stringableobjects call__toString(); arrays and objects are JSON-encoded - Unresolved keys (missing from context or no matching resolver) are left as the original
{key}token - When using custom
resolvers, the first matching resolver wins — later ones are not evaluated - Arrays and objects are JSON-encoded with JSON_PRETTY_PRINT by default. Pass a custom jsonResolverFlag per-logger to change the encoding flags
Custom logger implementation
Any class implementing LoggerInterface can be used as a destination. The simplest approach is to extend Psr\Log\NullLogger and override only log() — NullLogger provides no-op implementations of all the level-specific methods (debug(), info(), etc.) that forward to log().
The two built-in loggers follow the same pattern:
PhpErrorLogger— passes the formatted message toerror_log().InMemoryLogger— appends each record to a public$recordsarray; useful for testing.
LoggerFactory Constructor options
| Parameter | Default | Description |
|---|---|---|
$namespace |
'PluginNameSpace' |
Root namespace label |
$loggers |
[['logger' => NullLogger, 'logLevel' => ERROR]] |
One or more logger + level pairs |
$logLevel |
LogLevel::ERROR |
Default threshold for all loggers |
Per-logger options (inside $loggers entries)
| Key | Description |
|---|---|
logger |
Any LoggerInterface instance |
logLevel |
Minimum level for this logger. Available levels (high → low): emergency, alert, critical, error, warning, notice, info, debug |
breadcrumbMaxCount |
Max namespace segments shown (-1 = all, default -1) |
breadcrumbDirection |
Which end to trim: 'left' (default) or 'right' |
formatStr |
sprintf format string — receives LEVEL, namespace, message |
jsonResolverFlag |
json_encode flags for array/object placeholders (default JSON_PRETTY_PRINT) |
resolvers |
Custom [callable $test, callable $transform][] pairs for placeholder resolution |