
PSR Log
PHP interfaces that define a standard way for code to write log messages.php-fig/log
- Stars
- 10.4k
- Forks
- 194
- Licence
- MIT
- Language
- PHP
- Last update
- 9 months ago
- Type
- Library
What it is
This is a PHP package that contains the PSR-3 logging interface, a shared contract describing how a logger should be called. It is not a logger itself; it defines the methods a logger must have. Libraries can depend on it so they can accept any PSR-3-compatible logger without being tied to one implementation.
- Type-hint a constructor parameter as LoggerInterface so callers can pass any compatible logger
- Call $logger->info() or $logger->error() with a message and context array inside your code
- Implement LoggerInterface in your own code to create a custom logger
Great for
- PHP developers writing a library that needs to log without choosing a specific logging tool
- Teams building their own logger who want it to match the PSR-3 standard
- Developers using a framework or tool that expects a PSR-3 logger
Not ideal for
- People looking for a ready-to-use logger that writes to files: this package only provides the interface, so you need a separate implementation
- Non-PHP projects, since the package is written for PHP and installed with Composer
How to get it
- 1
Install with a package manager
You'll need: PHP · Composer
Install the package with Composer
composer require psr/log - 2
Run it
- Run composer require psr/log in your project folder.
- Type-hint a constructor parameter as Psr\Log\LoggerInterface.
- Call the logger methods such as info() or error() where needed.
- Install a PSR-3 implementation separately to actually write logs.
- 3
Get the most out of it
- Pair it with an existing PSR-3 implementation so your interface-typed code has a real logger behind it.
- Pass exception objects in the context array, as the README example does with the 'exception' key.
- Read the PSR-3 specification linked in the README for the exact expected behavior of each log level.
Downloads
Strengths
- Simple, small scope: it only defines the interface, so it adds little code to a project
- Lets libraries and applications swap logging implementations without changing calling code
- Widely referenced PHP standard with a public specification
Trade-offs
- Provides no logging output on its own; you must install an implementation separately
- The README example relies on an optional logger parameter, so you must handle the null case yourself
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| log (this) | 10.4k | Library | beginner | 9 months ago | PHP developers writing a library that needs to log without choosing a specific logging tool |
| monolog | 21.4k | Library | intermediate | 5 days ago | PHP developers who need structured logs from an application |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.