2017 © Pedro Peláez
 

library monolog-module

Monolog integration into Zend Framework

image

neeckeloo/monolog-module

Monolog integration into Zend Framework

  • Friday, October 27, 2017
  • by neeckeloo
  • Repository
  • 1 Watchers
  • 5 Stars
  • 32,192 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 8 Versions
  • 10 % Grown

The README.md

Monolog module for Laminas

Module to integrate Monolog with Laminas projects., (*1)

Build Status Latest Stable Version Total Downloads Coverage Status, (*2)

Requirements

Installation

MonologModule must be installed through Composer. For Composer documentation, please refer to getcomposer.org., (*3)

You can install the module from command line:, (*4)

$ composer require neeckeloo/monolog-module

Enable the module by adding MonologModule key in your application.config.php file., (*5)

Usage

Configuring a logger

This is the configuration of a logger that can be retrieved with key Log\App in the service manager. A channel name default is also defined to identify to which part of the application a record is related., (*6)

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
            ],
        ],
    ],
];

Adding a handler

The logger itself does not know how to handle a record. It delegates it to some handlers. The code above registers two handlers in the stack to allow handling records in two different ways., (*7)

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
                'handlers' => [
                    'stream' => [
                        'name' => StreamHandler::class,
                        'options' => [
                            'path'   => 'data/log/application.log',
                            'level'  => Logger::DEBUG,
                        ],
                    ],
                    'fire_php' => [
                        'name' => FirePHPHandler::class,
                    ],
                ],
            ],
        ],
    ],
];

Using processors

If you want to add extra information (tags, user IP, ...) to the records before they are handled, you should add some processors. The code above adds two processors that add an unique identifier and the current request URI, request method and client IP to a log record., (*8)

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
                'handlers' => [
                    'default' => [
                        'name' => StreamHandler::class,
                        'options' => [
                            'path'   => 'data/log/application.log',
                            'level'  => Logger::DEBUG,
                        ],
                    ],
                ],
                'processors' => [
                    UidProcessor::class,
                    WebProcessor::class,
                ],
            ],
        ],
    ],
];

You can also add processors to a specific handler., (*9)

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
                'handlers' => [
                    'default' => [
                        'name' => StreamHandler::class,
                        'options' => [
                            'path'   => 'data/log/application.log',
                            'level'  => Logger::DEBUG,
                        ],
                        'processors' => [
                            UidProcessor::class,
                            WebProcessor::class,
                        ],
                    ],
                ],
            ],
        ],
    ],
];

Retrieving a logger

Once the configuration is complete, you can retrieve an instance of the logger as below:, (*10)

$logger = $serviceManager->get('Log\App');
$logger->debug('debug message');

Testing

bash $ vendor/bin/phpunit, (*11)

Credits

License

The MIT License (MIT). Please see License File for more information., (*12)

The Versions

22/09 2016
26/07 2016
14/11 2014

v0.1.0

0.1.0.0 https://github.com/neeckeloo/MonologModule

Monolog integration into Zend Framework 2

  Sources   Download

MIT

The Requires

 

The Development Requires

logger log monolog zf2