2017 © Pedro Peláez
 

library logging

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

image

pluggit/logging

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  • Friday, March 9, 2018
  • by qu1m
  • Repository
  • 13 Watchers
  • 0 Stars
  • 8,662 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 25 % Grown

The README.md

Pluggit Logging

Build Status Scrutinizer Code Quality, (*1)

Logging gives you a simple abstraction compatible with PSR-3 logger interface that you can connect to a different backend to customize your logging needs, (*2)

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it., (*3)

Installation

Require the library as usual:, (*4)

``` bash composer require "pluggit/logging", (*5)


## Monolog This library provides [Monolog](https://github.com/Seldaek/monolog) as its main logging backend. You will need to install the library manually: ``` bash composer require monolog/monolog ^1.2

To create factory, set default channel name as first parameter and Formatter as second one., (*6)

<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;
$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));

Handlers

The library provides a factory to ease the addition of some handlers to the logger objects,, (*7)

Built in handlers

  • RotatingFileHandler
    This handler will write the log messages to a file, rotating the name depending on the given date format
<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;
use Monolog\Logger;

$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));

// addRotatingFileHandlerBuilder(directory path, date format, max files number, file name, file name format, level)
$logger->addRotatingFileHandlerBuilder('directory/path','Y-m-d', 14, '{channel}.log', '{date}_{filename}', Logger::ERROR);
  • SyslogUdpHandler
    This handler will send a UDP packet with the log message, useful to send messages to 3rd party log platforms or storage servers (like ElasticSearch)
<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;

$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));

//addSyslogUdpHandlerBuilder(syslog UDP Host, syslog UDP Port, level)
$logger->addSyslogUdpHandlerBuilder('12.34.56.78', '90', Logger::ERROR);

Adding custom handler

To add custom handler you should write handler builder implementing HandlerBuilderInterface:, (*8)

<?php
namespace Cmp\Logging\Monolog\Handler;

use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\AbstractHandler;

interface HandlerBuilderInterface
{
    /**
     * @param string             $channelName
     * @param array              $processors
     * @param FormatterInterface $formatter
     *
     * @return AbstractHandler
     */
    public function build($channelName, FormatterInterface $formatter, $processors = []);
}

The handler builder should be added using addHandlerBuilder method:, (*9)

<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;
use Customer\Namespace\CustomHandlerBuilder;

$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));
$handlerBuilder = new CustomHandlerBuilder($param1, $param2);
$logger->addHandlerBuilder($handlerBuilder);

Error handler

To add default error handler use addErrorHandlerBuilder method., (*10)

<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;
use Customer\Namespace\CustomHandlerBuilder;

$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));
$handlerBuilder = new CustomHandlerBuilder($param1, $param2);
$logger->addErrorHandlerBuilder($handlerBuilder);

Processors

<?php
use Cmp\Logging\Monolog\LoggingFactory;
use Monolog\Formatter\JsonFormatter;
use Customer\Namespace\CustomHandlerBuilder;
use Monolog\Logger\GitProcessor;

$logger = new LoggingFactory('yoursite', 'error_channel', new JsonFormatter(true));
//addProcessor(callable $processor)
$logger->addProcessor(new GitProcessor(Logger:DEBUG));

The Versions

09/03 2018

dev-master

9999999-dev

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

09/03 2018

1.0.8

1.0.8.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

28/08 2017

dev-feature/WHD-518

dev-feature/WHD-518

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

28/08 2017

1.0.7

1.0.7.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

05/07 2017

1.0.6

1.0.6.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

05/07 2017

dev-tests

dev-tests

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

05/07 2017

1.0.5

1.0.5.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

04/07 2017

1.0.4

1.0.4.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

13/02 2017

1.0.3

1.0.3.0

Logging provides a thin PSR-7 interface abstraction to connect any logging facility behind it.

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

08/02 2017
16/01 2017
16/01 2017

dev-feature/WQR-2254

dev-feature/WQR-2254

Logging abstraction layer

  Sources   Download

MIT

The Requires

 

The Development Requires

by jaroslawgabaracmp

30/09 2016