2017 © Pedro Peláez
 

library zf2-graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

image

debugger84/zf2-graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  • Wednesday, August 9, 2017
  • by debugger84
  • Repository
  • 1 Watchers
  • 0 Stars
  • 932 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 69 % Grown

The README.md

Graylog2 for Zend Framework 2

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application, using bzikarsky/gelf-php: the newer version of deprecated Graylog2/gelf-php library., (*1)

Install

composer require debugger84/zf2-graylog:dev-master

Add values of graylog connection to your config, (*2)

    'graylog' => [
        'host' => 'http://graylog.local',
        'port' => 12222,
        'facility' => 'Your project name'
    ],

Rewrite factory for Zend Logger interface, (*3)

\Zend\Log\LoggerInterface::class => \ZF2Graylog\Factory\LoggerFactory::class,

Usage

I added a method to a custom base controller:, (*4)

class Base extends \Zend\Mvc\Controller\AbstractActionController {
    private $logger;

    protected function getLogger() {
        if (!isset($this->logger)) {
            $this->logger = new \Zend\Log\Logger;

            // __construct($facility, $hostname, $port)
            $writer = new \ZF2Graylog\Log\Writer\Graylog2('ZF2', '127.0.0.1');
            $this->logger->addWriter($writer);
        }

        return $this->logger;
    }
}

Which can then be used as usual:, (*5)

$this->getLogger()->info('Informative message');

The formatter should (or will) support error logging (as below) by mapping the following attributes to their respective GELF fields:, (*6)

$logger = new \Zend\Log\Logger;
$writer = new \ZF2Graylog\Log\Writer\Graylog2('ZF2', '127.0.0.1');
$logger->addWriter($writer);

Zend\Log\Logger::registerErrorHandler($logger);


Zend\Log        GELFMessage
--------------------------------------------------------------------------------
message         message, full_message, short_message (unless present in $values)
errno           level
file            file
line            line
context         additional fields (to be tested)

Additional fields that are associated with GELF fields:, (*7)

  • full (message) is mapped to full_message (if present, otherwise message)
  • short (message) is mapped to short_message (if present, otherwise message)
  • version is mapped to version (not set if not present)
  • facility is mapped to facility. A default facility is set in the writer.
  • Additional fields are mapped as additional fields.

Todo

  • Write a composer.json that includes the Graylog2/gelf-php lib.
  • Docblocks.
  • Further testing of different events.
  • Check errno maps to the correct severity level when used as an errorHandler.

License

TBC, will probably be MIT., (*8)

The Versions

09/08 2017

dev-zf2.4

dev-zf2.4 https://github.com/debugger84/ZF2Graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  Sources   Download

MIT

The Requires

 

log logging zf2

08/08 2017

dev-master

9999999-dev https://github.com/debugger84/ZF2Graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  Sources   Download

MIT

The Requires

 

log logging zf2

03/07 2017

2.2.0

2.2.0.0 https://github.com/debugger84/ZF2Graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  Sources   Download

MIT

The Requires

 

log logging zf2

03/04 2013

2.1.0

2.1.0.0 https://github.com/rmasters/ZF2Graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  Sources   Download

MIT

The Requires

 

log logging zf2

07/01 2013

2.0.4

2.0.4.0 https://github.com/rmasters/ZF2Graylog

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

  Sources   Download

MIT

The Requires

 

log logging zf2