psr/log

The PSR-3 common logger interface that lets PHP libraries accept any logger without depending on a specific implementation.

Library
Composer
v3.0.2
10,419stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity4
Maintenance20
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture65
Code Quality75
Innovation55
Learning Curve90

psr/log is the reference implementation of PSR-3, the PHP-FIG standard that defines a common LoggerInterface for logging libraries. It ships no logging backend of its own — no file writers, no formatters — only the interface, a LogLevel constants class, an AbstractLogger/LoggerTrait base implementation, a NullLogger no-op, and a LoggerAwareInterface/LoggerAwareTrait pair for injecting a logger into consumer classes. Because nearly every major PHP framework and logging library (Monolog, Symfony, Laravel’s underlying stack, Guzzle) type-hints against Psr\Log\LoggerInterface rather than a concrete class, packages that accept a PSR-3 logger can be wired up to whichever logging implementation the application already uses, with zero coupling to that implementation’s internals.

What You Get

  • Psr\Log\LoggerInterface with the eight RFC 5424 severity levels (emergency, alert, critical, error, warning, notice, info, debug) plus a generic log($level, $message, $context) method
  • Psr\Log\LogLevel — a constants class enumerating the eight level strings for type-safe comparisons
  • Psr\Log\AbstractLogger and Psr\Log\LoggerTrait — base implementations that let you implement only log() and get the eight level-specific methods for free
  • Psr\Log\NullLogger — a no-op implementation for disabling logging or satisfying a required constructor argument in tests
  • Psr\Log\LoggerAwareInterface and Psr\Log\LoggerAwareTrait — a standard setLogger() contract for injecting a logger into any class after construction

Common Use Cases

  • Accepting an optional logger constructor argument in a library so consumers can plug in Monolog, Symfony’s logger, or any PSR-3-compatible implementation
  • Writing framework-agnostic packages that need to emit log messages without pulling in a concrete logging dependency
  • Using NullLogger as a safe default when no logger is configured, avoiding null checks scattered through the codebase
  • Implementing LoggerAwareInterface so a DI container can inject a logger into any service that declares the trait

Under The Hood

Architecture - The package is purely a set of interfaces, a small enum-like constants class (LogLevel), and thin trait/abstract-class helpers; there is no runtime logic beyond LoggerTrait::log() delegating to the appropriate level method and NullLogger swallowing all calls. Consumers depend on LoggerInterface and receive whatever concrete logger implementation (e.g. Monolog) the application wires in, so the actual log-writing behavior lives entirely outside this repository. Tech Stack - Plain PHP 8+ with PSR-4 autoloading (Psr\Log\ mapped to src/) and no runtime dependencies at all; the package only declares a php: >=8.0.0 platform requirement in composer.json. Code Quality - The codebase is deliberately minimal — eight small files, each under 100 lines, with typed method signatures and PHPDoc blocks on every interface method describing expected $level, $message, and $context semantics; there is no test suite in the repository since there is no executable behavior to test beyond NullLogger and LoggerTrait, which are exercised indirectly by every downstream implementation’s own test suite. API Design - The interface mirrors the RFC 5424 syslog severity levels exactly, which any PHP developer already familiar with logging conventions will recognize instantly; the eight level methods plus one generic log() method give implementers freedom in how messages are formatted while giving consumers a single, ubiquitous type to depend on.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search