gdpro / gdpro-monolog

Monolog integration for ZF2


Gdpro Monolog

Introduction

The repository adds support for logging to Monolog to the Zend Framework 2.

Changelog

doc/CHANGELOG.md

Requirements

Please see the composer.json file.

Installation

Run the following composer command:

$ composer require "gdpro/gdpro-monolog:~1.0"

Alternately, manually add the following to your composer.json, in the require section:

"require": {
    "gdpro/gdpro-monolog": "^1.0"
}

And then run composer update to ensure the module is installed.

Finally, add the module name to your project's config/application.config.php under the modules key:

return array(
    /* ... */
    'modules' => array(
        /* ... */
        'GdproMonolog',
    ),
    /* ... */
);

Documentation

By Default the monolog logging will log your error event and add them to the log files

  • data/log/route.error.log
  • data/log/dispatch.error.log
  • data/log/

Utilisation

Default Logger

$this->getServiceLocator()->get('gdpro-monolog_default')->addDebug('hello {contextvar}', ['contextvar' => 'world']);

Exception Logger

$this->getServiceLocator()->get('my_awesome_customized_logger')->addDebug('hello {contextvar}', ['contextvar' => 'world']); /** * @param MvcEvent $event */ public function onBootstrap(MvcEvent $event) { $eventManager = $event->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager);

$eventManager->attach(MvcEvent::EVENT_FINISH, [$this, 'onFinish']); $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, [$this, 'onRenderError']); $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'onDispatchError']); }

public function onFinish(MvcEvent $event) { $services = $event->getApplication()->getServiceManager(); $services->get(CheckSlowResponseTimeListener::class); $services->get(LogMemoryUsageListener::class); }

public function onRenderError(MvcEvent $event) { $services = $event->getApplication()->getServiceManager(); $services->get(LogRenderErrorListener::class); }

public function onDispatchError(MvcEvent $event) { $services = $event->getApplication()->getServiceManager(); $services->get(LogDispatchErrorListener::class); }

The MIT License (MIT)

Copyright (c) 2014 gdpro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
php composer.phar require "gdpro/gdpro-monolog"

Require

  • php: >=5.5.8
  • psr/log: ^1.0
  • monolog/monolog: ^1.22

Require Dev

  • zendframework/zend-stdlib: ^3.1
  • zendframework/zend-modulemanager: ^2.7
  • zendframework/zend-servicemanager: ^3.2
  • zendframework/zend-eventmanager: ^3.1
  • zendframework/zend-mvc: ^3.0
  • phpunit/phpunit: ~4.3
  • squizlabs/php_codesniffer: ^2.2