Logging driver for CommonPHP that wraps Monolog for configurable PSR-3 logging.
- PHP
^8.5 comphp/logging:^0.3monolog/monolog
Once this package is available through your Composer repositories, install it with:
composer require comphp/logging-monolog<?php
use CommonPHP\Drivers\Logging\Monolog\MonologDriverOptions;
use CommonPHP\Drivers\Logging\Monolog\MonologHandlerFactory;
use CommonPHP\Drivers\Logging\Monolog\MonologLogDriver;
use CommonPHP\Logging\LogManager;
$handlers = new MonologHandlerFactory();
$logger = new LogManager(new MonologLogDriver(options: new MonologDriverOptions(
channel: 'app',
handlers: [
$handlers->file(__DIR__ . '/var/app.log'),
],
)));
$logger->info('User {user} logged in.', ['user' => 'ada']);This driver is intended to let CommonPHP Logging use Monolog handlers, processors, formatters, and channels without making the core logging package depend directly on Monolog.
Applications may use this driver when they need production-ready logging targets, rotation, formatting, or integrations that Monolog already supports.
MonologLoggerFactory, MonologHandlerFactory, MonologFormatterFactory, and MonologProcessorFactory provide small helpers for common setup while still allowing applications to pass native Monolog objects directly.
Logger setup, handler, formatting, write, and configuration failures should throw CommonPHP logging driver exceptions when logging cannot be completed or configured safely.
MIT. See LICENSE.md.