Home

PSR3

PSR-3, short for PHP Standards Recommendation 3, defines a standard logging interface for PHP libraries and applications. Published by the PHP Framework Interop Group (PHP-FIG), it aims to enable interoperable logging by ensuring that libraries can log messages in a consistent way regardless of the underlying logging implementation.

The core of PSR-3 is the LoggerInterface, named Psr\Log\LoggerInterface. It requires eight convenience methods—emergency(), alert(), critical(),

Adoption and usage: By type-hinting dependencies on Psr\Log\LoggerInterface, code can work with any PSR-3 compliant logger.

History and scope: PSR-3 is one of several PHP-FIG PSRs designed to standardize common interfaces. It has

error(),
warning(),
notice(),
info(),
and
debug()—one
for
each
severity
level,
plus
a
generic
log($level,
$message,
array
$context
=
array())
method.
Implementations
must
accept
a
message
string
and
an
optional
associative
context
array
used
for
contextual
data
and
message
interpolation.
The
$level
parameter
in
log()
is
expected
to
be
one
of
the
defined
levels,
typically
as
a
string,
though
implementations
may
extend
or
map
levels
as
needed.
This
promotes
substitutability
and
reduces
coupling
between
libraries
and
their
logging
backends.
Many
PHP
logging
libraries—most
notably
Monolog—provide
PSR-3
compatible
implementations,
and
major
frameworks
offer
PSR-3
compatible
adapters
and
services.
become
a
foundational
component
in
PHP
ecosystems,
encouraging
consistent
logging
practices
across
projects.