Documentation

Logger
in package
implements LoggerInterface

Logger class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

Table of Contents

Interfaces

LoggerInterface

Constants

ALERT  = \Psr\Log\LogLevel::ALERT
CRITICAL  = \Psr\Log\LogLevel::CRITICAL
DEBUG  = \Psr\Log\LogLevel::DEBUG
EMERGENCY  = \Psr\Log\LogLevel::EMERGENCY
Constants for log levels (PSR-3 level strings)
ERROR  = \Psr\Log\LogLevel::ERROR
INFO  = \Psr\Log\LogLevel::INFO
NOTICE  = \Psr\Log\LogLevel::NOTICE
WARNING  = \Psr\Log\LogLevel::WARNING
RESERVED_CONTEXT_KEYS  = ['timestamp', 'name', 'format']
Reserved context keys never treated as interpolation placeholders

Properties

$processors  : array<string|int, callable>
Context-enrichment processors
$timestampFormat  : string
Log timestamp format
$writers  : array<string|int, mixed>
Log writers

Methods

__construct()  : mixed
Constructor
addProcessor()  : Logger
Add a context-enrichment processor
addProcessors()  : Logger
Add context-enrichment processors
addWriter()  : Logger
Add a log writer
addWriters()  : Logger
Add log writers
alert()  : void
Add an ALERT log entry
critical()  : void
Add a CRITICAL log entry
debug()  : void
Add a DEBUG log entry
emergency()  : void
Add an EMERGENCY log entry
error()  : void
Add an ERROR log entry
getLevel()  : string
Get level display name
getLogLevel()  : string
Static method to get log level display name
getProcessors()  : array<string|int, callable>
Get all context-enrichment processors
getTimestampFormat()  : string
Get timestamp format
getWriters()  : array<string|int, mixed>
Get all log writers
info()  : void
Add an INFO log entry
log()  : void
Add a log entry
notice()  : void
Add a NOTICE log entry
setLogLimit()  : Logger
Set log level limit for all log writers
setTimestampFormat()  : Logger
Set timestamp format
warning()  : void
Add a WARNING log entry
interpolate()  : array<string|int, mixed>
Substitute {key} placeholders in the message from scalar/Stringable context values.

Constants

ALERT

public mixed ALERT = \Psr\Log\LogLevel::ALERT

CRITICAL

public mixed CRITICAL = \Psr\Log\LogLevel::CRITICAL

DEBUG

public mixed DEBUG = \Psr\Log\LogLevel::DEBUG

EMERGENCY

Constants for log levels (PSR-3 level strings)

public string EMERGENCY = \Psr\Log\LogLevel::EMERGENCY

ERROR

public mixed ERROR = \Psr\Log\LogLevel::ERROR

INFO

public mixed INFO = \Psr\Log\LogLevel::INFO

NOTICE

public mixed NOTICE = \Psr\Log\LogLevel::NOTICE

WARNING

public mixed WARNING = \Psr\Log\LogLevel::WARNING

RESERVED_CONTEXT_KEYS

Reserved context keys never treated as interpolation placeholders

protected array<string|int, mixed> RESERVED_CONTEXT_KEYS = ['timestamp', 'name', 'format']

Properties

$processors

Context-enrichment processors

protected array<string|int, callable> $processors = []

$timestampFormat

Log timestamp format

protected string $timestampFormat = 'Y-m-d H:i:s'

$writers

Log writers

protected array<string|int, mixed> $writers = []

Methods

__construct()

Constructor

public __construct([WriterInterface|array<string|int, mixed>|null $writer = [] ][, string $timestampFormat = 'Y-m-d H:i:s' ]) : mixed

Instantiate the logger object

Parameters
$writer : WriterInterface|array<string|int, mixed>|null = []
$timestampFormat : string = 'Y-m-d H:i:s'

addProcessor()

Add a context-enrichment processor

public addProcessor(callable $processor) : Logger
Parameters
$processor : callable
Return values
Logger

addProcessors()

Add context-enrichment processors

public addProcessors(array<string|int, mixed> $processors) : Logger
Parameters
$processors : array<string|int, mixed>
Return values
Logger

addWriters()

Add log writers

public addWriters(array<string|int, mixed> $writers) : Logger
Parameters
$writers : array<string|int, mixed>
Return values
Logger

alert()

Add an ALERT log entry

public alert(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

critical()

Add a CRITICAL log entry

public critical(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

debug()

Add a DEBUG log entry

public debug(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

emergency()

Add an EMERGENCY log entry

public emergency(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

error()

Add an ERROR log entry

public error(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

getLevel()

Get level display name

public getLevel(string|int $level) : string

Accepts either a PSR-3 level string or a legacy severity int (0-7).

Parameters
$level : string|int
Return values
string

getLogLevel()

Static method to get log level display name

public static getLogLevel(string|int $level) : string
Parameters
$level : string|int
Return values
string

getProcessors()

Get all context-enrichment processors

public getProcessors() : array<string|int, callable>
Return values
array<string|int, callable>

getTimestampFormat()

Get timestamp format

public getTimestampFormat() : string
Return values
string

getWriters()

Get all log writers

public getWriters() : array<string|int, mixed>
Return values
array<string|int, mixed>

info()

Add an INFO log entry

public info(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

log()

Add a log entry

public log(mixed $level, string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

$level stays untyped/mixed to match Psr\Log\LoggerInterface::log() exactly (PHP forbids narrowing an interface parameter's type). Accepts a PSR-3 level string or a legacy severity int (0-7). Registered processors enrich $context before interpolation runs.

Parameters
$level : mixed
$message : string|Stringable
$context : array<string|int, mixed> = []

notice()

Add a NOTICE log entry

public notice(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

setLogLimit()

Set log level limit for all log writers

public setLogLimit(string|int $level) : Logger
Parameters
$level : string|int
Return values
Logger

setTimestampFormat()

Set timestamp format

public setTimestampFormat([string $format = 'Y-m-d H:i:s' ]) : Logger
Parameters
$format : string = 'Y-m-d H:i:s'
Return values
Logger

warning()

Add a WARNING log entry

public warning(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

interpolate()

Substitute {key} placeholders in the message from scalar/Stringable context values.

protected interpolate(string $message, array<string|int, mixed> $context) : array<string|int, mixed>

Reserved keys (timestamp, name, format) are never treated as placeholders, since they're Logger-managed metadata rather than user-supplied context. Consumed keys are removed from the returned context so writers don't also serialize a value that's already inline in the message.

Parameters
$message : string
$context : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results