Monolog Factories for Laminas and Mezzio
This library was inspired by psr11-monolog and monolog-factory.
Run
composer require mimmi20/monolog-laminas-factory
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/logger.config.php
config/autoload/monolog.global.php
<?php
return [
'log' => [
\Laminas\Log\Logger::class => [
'name' => 'name',
'exceptionhandler' => false,
'errorhandler' => false,
'shutdownhandler' => false,
'writers' => [], // Writers for Laminas Log
'processors' => [], // Processors for Laminas Log
'handlers' => [ // Handlers for Monolog
// At the bare minimum you must include a default handler config.
// Otherwise log entries will be sent to the void.
'default' => [
'type' => 'stream',
'enabled' => true,
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
// Another Handler
'myOtherHandler' => [
'type' => 'stream',
'enabled' => false,
'options' => [
'stream' => '/var/log/someother-log-file.txt',
],
],
],
'monolog_processors' => [], // Processors for Monolog
],
],
];
A minimal configuration would consist of at least one default handler and one named service. Please note that if you don't specify a default handler a NullHandler will be used when you wire up the default logger.
<?php
return [
'log' => [
\Laminas\Log\Logger::class => [
'name' => 'name',
'handlers' => [
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
],
],
],
];
<?php
return [
'log' => [
\Laminas\Log\Logger::class => [
'name' => 'name',
'handlers' => [
'default' => [
// A Handler type or pre-configured service from the container
'type' => 'stream',
// Handler specific options. See handlers below
'options' => [
'stream' => '/tmp/log_one.txt',
// Optional: Formatter for the handler.
'formatter' => [
'type' => 'line',
// formatter specific options. See formatters below
'options' => [],
],
// Optional: Processor for the handler
'processors' => [
[
// A processor type or pre-configured service from the container
'type' => 'psrLogMessage',
// processor specific options. See processors below
'options' => [],
],
],
],
],
],
// Processors for Monolog/Logger
'monolog_processors' => [
// Array Keys are the names used for the processors
'processorOne' => [
// A processor type or pre-configured service from the container
'type' => 'psrLogMessage',
// processor specific options. See processors below
'options' => [],
],
],
],
],
];
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.