monolog
Sends your logs to files, sockets, inboxes, databases and various web services
Monolog is a PHP library for recording logs from your application to multiple destinations at once, files, email, databases, or monitoring services, through a pluggable handler system.
Monolog is a PHP logging library — a tool for recording events, errors, and diagnostic messages from your application to a variety of destinations. Rather than using PHP's built-in error logging (which only writes to a single file), Monolog lets you send log messages to multiple places simultaneously and in different formats.
The library uses a concept called "handlers" — pluggable components that each know how to send a log message somewhere. You stack multiple handlers on a logger, and each message flows through them. Destinations include local files, system log sockets, email inboxes, databases, and many external web services and monitoring platforms. You can also attach "processors" that add extra information to log records (like the current user, request ID, or memory usage) and "formatters" that control how the output looks.
Monolog implements PSR-3, which is a community standard interface for PHP loggers. Because it follows this standard, it integrates out of the box with many popular PHP frameworks, including Symfony, Laravel, and others — those frameworks use Monolog as their built-in logger.
The library handles standard log severity levels (debug, info, warning, error, critical, etc.), and you can configure each handler to only process messages above a certain severity. Monolog version 3 requires PHP 8.1 or later. You install it using Composer, the standard PHP package manager. It is open source under the MIT license.
Where it fits
- Send application errors to a log file and an email inbox at the same time using stacked handlers.
- Automatically attach contextual data like request IDs or memory usage to every log entry via processors.
- Integrate structured logging into a Symfony or Laravel application using Monolog as the built-in logger.
- Route only critical-severity messages to an external monitoring service while keeping debug logs local.