mimmi20 / monolog-laminas-factory
Provides a Factory to build a Laminas Logger using Monolog.
Installs: 8 895
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1.0
- ext-mbstring: *
- laminas/laminas-log: ^2.15.2
- monolog/monolog: ^2.8.0
Requires (Dev)
- actived/microsoft-teams-notifier: ^1.2.0
- aws/aws-sdk-php: ^3.231.18
- bartlett/monolog-callbackfilterhandler: ^2.1.0
- cmdisp/monolog-microsoft-teams: ^1.2.0
- doctrine/couchdb: 1.0.0-beta4
- elasticsearch/elasticsearch: ^v7.17.0 || ^v8.3.2
- graylog2/gelf-php: ^1.7.1
- guzzlehttp/guzzle: ^7.4.5
- guzzlehttp/psr7: ^2.4.0
- jk/monolog-request-header-processor: ^1.0.0
- laminas/laminas-config: ^3.7.0
- laminas/laminas-dependency-plugin: ^2.2.0
- laminas/laminas-eventmanager: ^3.5.0
- laminas/laminas-modulemanager: ^2.11.0
- laminas/laminas-servicemanager: ^3.16.0
- mikey179/vfsstream: ^1.6.11
- mimmi20/coding-standard: ^3.0.3
- mimmi20/monolog-streamformatter: ^1.0.0 || ^2.0.0
- php-amqplib/php-amqplib: ^3.2.0
- php-console/php-console: ^3.1.8
- phpstan/extension-installer: ^1.1.0
- phpstan/phpstan: ^1.8.2
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-phpunit: ^1.1.1
- phpunit/phpunit: ^9.5.21
- predis/predis: ^1.1.10 || ^2.0.0
- rollbar/rollbar: ^v2.1.0 || ^v3.1.3
- ruflin/elastica: ^7.2.0
- swiftmailer/swiftmailer: ^6.3.0
- symfony/mailer: ^v6.1.3
- symfony/mime: ^v6.1.3
Suggests
- ext-amqp: Allow sending log messages to an AMQP server (1.0+ required)
- ext-json: Allow sending log messages to the ChromePHP Handler
- ext-mongodb: Allow sending log messages to a MongoDB server (via driver)
- ext-sockets: Allow sending log messages to a Syslog server (via UDP driver)
- actived/microsoft-teams-notifier: Allow sending log messages to Microsoft Teams
- aws/aws-sdk-php: Allow sending log messages to AWS services like DynamoDB
- bartlett/monolog-callbackfilterhandler: Allow filtering log messages based on a callback function
- cmdisp/monolog-microsoft-teams: Allow sending log messages to Microsoft Teams
- doctrine/couchdb: Allow sending log messages to a CouchDB server
- elasticsearch/elasticsearch: Allow sending log messages to an Elasticsearch server via official client
- graylog2/gelf-php: Allow sending log messages to a GrayLog2 server
- jk/monolog-request-header-processor: Allow to add request headers to the log message
- laminas/laminas-servicemanager: Required for the Factories
- mongodb/mongodb: Allow sending log messages to a MongoDB server (via library)
- php-amqplib/php-amqplib: Allow sending log messages to an AMQP server using php-amqplib
- rollbar/rollbar: Allow sending log messages to Rollbar (only 2.1+ supported, but not 3.x)
- ruflin/elastica: Allow sending log messages to an Elastic Search server
README
Monolog Factories for Laminas and Mezzio
This library was inspired by psr11-monolog and monolog-factory.
Code Status
Table of Contents
Installation
Run
composer require mimmi20/monolog-laminas-factory
Usage with Laminas and Mezzio
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
Configuration
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 ], ], ];
Minimal Configuration
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.
Minimal Example (using Mezzio for the example)
<?php return [ 'log' => [ \Laminas\Log\Logger::class => [ 'name' => 'name', 'handlers' => [ 'default' => [ 'type' => 'stream', 'options' => [ 'stream' => '/var/log/some-log-file.txt', ], ], ], ], ], ];
Full Configuration
Full Example
<?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' => [], ], ], ], ], ];
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.