2017 © Pedro Peláez
 

library zend-logger

Few helpers for easy looging in Zend Framework 2

image

nemutaisama/zend-logger

Few helpers for easy looging in Zend Framework 2

  • Tuesday, June 28, 2016
  • by Nemutaisama
  • Repository
  • 1 Watchers
  • 0 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ZendLogger

Integration of any PSR-3 logger to ZendFramework2 projects. This package allow you easily log errors through EventManager., (*1)

INSTALL

The recommended way to install is through composer., (*2)

{
    "require": {
        "nemutaisama/zend-logger": "*@dev"
    }
}

or just, (*3)

composer require nemutaisama/zend-logger:*@dev, (*4)

USAGE

  1. Add ZendLogger to your config/application.config.php to enable module., (*5)

  2. Configure any PSR-3 log service, and register it in ServiceManager., (*6)

  3. Copy the config file config/zendlogger.global.php.dist from the module to config/autoload your project., (*7)

At this moment config is pretty simple - just set name of your log service. Default config use EnliteMonolog package with service name from default config., (*8)

    'ZendLogger' => 'YourLoggerServiceName'

Now you can use it., (*9)

This package come with set of ControllerPlugins and trait for model. From controller you can just use it., (*10)

class IndexController extends AbstractActionController {

    public function indexAction(){
        ...
        $this->debug('message', [context]);
        $this->info('message', [context]);
        $this->notice('message', [context]);
        $this->warning('message', [context]);
        $this->error('message', [context]);
        $this->critical('message', [context]);
        $this->alert('message', [context]);
        $this->emergency('message', [context]);
        $this->log($level, 'message', [context]);
        ...
    }
}

From model classes you can just use trait. Since package use EventManager you should have it available in class. For example by simply use Zend\EventManager\EventManagerAwareTrait. After that usage is same as in controller., (*11)

namespace MyPackage;

use ZendLogger\LoggerTrait;
use Zend\EventManager\EventManagerAwareTrait;

class MyModel {

    use LoggerTrait;
    use EventManagerAwareTrait;

    public function logErrors(){
        ...
        $this->debug('message', [context]);
        $this->info('message', [context]);
        $this->notice('message', [context]);
        $this->warning('message', [context]);
        $this->error('message', [context]);
        $this->critical('message', [context]);
        $this->alert('message', [context]);
        $this->emergency('message', [context]);
        $this->log($level, 'message', [context]);
        ...
    }
}

Events

You can also handle errors for anything else hooking events from shared event manager, (*12)

    public function attach(EventManagerInterface $events)
    {
        $sharedEvents = $events->getSharedManager();
        $this->listeners[] = $sharedEvents->attach('*', 'log.emergency', array($this, 'onEmergency'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.alert', array($this, 'onAlert'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.critical', array($this, 'onCritical'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.error', array($this, 'onError'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.warning', array($this, 'onWarning'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.notice', array($this, 'onNotice'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.info', array($this, 'onInfo'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.debug', array($this, 'onDebug'), 100);
        $this->listeners[] = $sharedEvents->attach('*', 'log.message', array($this, 'onMessage'), 100);
    }

The Versions

28/06 2016

dev-master

9999999-dev

Few helpers for easy looging in Zend Framework 2

  Sources   Download

MIT

The Requires

 

by Andrey Ageev

log zend framework 2