2017 © Pedro Peláez
 

library logger-client

Client side logger

image

fei/logger-client

Client side logger

  • Tuesday, June 12, 2018
  • by rwellens
  • Repository
  • 25 Watchers
  • 0 Stars
  • 149 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 40 Versions
  • 2 % Grown

The README.md

Logger Client

GitHub licensecontinuousphpGitHub issues, (*1)

Installation

Just add the following requirement to your composer.json file:, (*2)

    "fei/logger-client": "^1.2.0"

Configuration

The logger client needs some options to work properly. The available options that can be passed to the __construct() or setOptions() methods are :, (*3)

Option Description Type Possible Values Default
OPTION_BASEURL This is the server to which send the requests. string Any URL, including protocol but excluding path --
OPTION_FILTER Minimum notification level required for notifications to be actually sent. int Any Notification::LVL_* constant Notification::LVL_ERROR
OPTION_BACKTRACE Should backtrace be added to notifications before they are sent. bool true / false true
OPTION_LOGFILE File path and name where the Logger will store its own exceptions. string Any writeable file path /tmp/logger.log
OPTION_HEADER_AUTHORIZATION Api Key for authentification string Any string value ''

Notes: Logger is an alias of Fei\Service\Logger\Client\Logger Notification is an alias of Fei\Service\Logger\Entity\Notification, (*4)

Usage

Initialization

A Logger client should always be initialized by a dependency injection component, since it requires at least one dependency, which is the transport. Moreover, the BASEURL parameter should also depends on environment., (*5)

// sample configuration for production environment
$logger = new Logger(array(
                            Logger::OPTION_BASEURL  => 'http://logger.flash-global.net',
                            Logger::OPTION_FILTER   => Notification::LVL_DEBUG,
                          )
                    );
// inject transport classes
$logger->setTransport(new BasicTransport());

// optionnal asynchronous transport, that will be automatically used to push notifications
//
// NOTE this transport requires a beanstalk queue able to listen to its requests
$pheanstalk = new Pheanstalk('localhost');
$asyncTransport = new BeanstalkProxyTransport;
$asyncTransport->setPheanstalk($pheanstalk);
$logger->setAsyncTransport($asyncTransport);

Pushing a simple notification

Once you have set up the Logger, you can start pushing notifications by calling the notify() method on the Logger:, (*6)


$logger = $container->get('logger'); $logger->notify('Notification message'); // default level is Notification::LVL_INFO $logger->notify('Debug message', array('level' => Notification::LVL_DEBUG));

While its possible to pass more than just the level using the second (array) parameter, it is recommended not to do so. If you want to pass more informations, like a context, please take a look at the following section., (*7)

Pushing a Notification instance

The more reliable way to push a notification is to instantiate it by yourself, and then send it through notify(), that will also accept Notification instances:, (*8)


$logger = $container->get('logger'); $notification = new Notification(array('message' => 'Notification message')); $notification ->setLevel(Notification::LVL_WARNING) ->setContext(array('key' => 'value') ; $logger->notify($notification);

PSR-3 Adapter

PSR-3 describe an interface for logging purpose to ensure interoperability between systems., (*9)

For this end we provide the adapter Fei\Service\Logger\Client\Psr\PsrLoggerAdapter., (*10)

<?php

use Fei\Service\Logger\Client\Logger;
use Fei\Service\Logger\Client\Psr\PsrLoggerAdapter;

$logger = new Logger();

$psr = new PsrLoggerAdapter($logger);

$psr->error('This is a error message');

It's always possible to set category, namespace and other notification properties with log context:, (*11)

<?php

use Fei\Service\Logger\Client\Logger;
use Fei\Service\Logger\Client\Psr\PsrLoggerAdapter;
use Fei\Service\Logger\Entity\Notification;

$logger = new Logger();

$psr = new PsrLoggerAdapter($logger);

$psr->error(
    'This is a error message',
    [
        'namespace' => '/my/app',
        'category' => Notification::TRACKING,
        'key1' => 'value1',
        'key2' => 'value2'
    ]
);

Manageable Notification properties are flag, namespace, user, server, command, origin, category and env. Another key of context will be set in Notification context., (*12)

The Versions

29/05 2018

dev-feature/add_api_key

dev-feature/add_api_key

Client side logger

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

20/03 2018
14/02 2018

v1.2.10

1.2.10.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

10/01 2018

dev-feature/update_composer_api_client

dev-feature/update_composer_api_client

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

27/06 2017

v1.2.9

1.2.9.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

25/10 2016

v1.2.8

1.2.8.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

20/09 2016

v1.2.7

1.2.7.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

30/08 2016

v1.2.6

1.2.6.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

30/08 2016

v1.2.5

1.2.5.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

17/08 2016

v1.2.4

1.2.4.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

28/07 2016

v1.2.3

1.2.3.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

28/07 2016

v1.2.2

1.2.2.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

25/07 2016

v1.2.1

1.2.1.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

25/07 2016

v1.2.0

1.2.0.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

25/07 2016

v1.1.14

1.1.14.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

25/07 2016

v1.1.13

1.1.13.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.12

1.1.12.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.11

1.1.11.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.10

1.1.10.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.9

1.1.9.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.8

1.1.8.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.7

1.1.7.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.6

1.1.6.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

19/07 2016

v1.1.5

1.1.5.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

18/07 2016

v1.1.4

1.1.4.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

18/07 2016

v1.1.3

1.1.3.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

18/07 2016

v1.1.2

1.1.2.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

18/07 2016

v1.1.1

1.1.1.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

17/07 2016

v1.1.0

1.1.0.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

15/07 2016

v1.0.8

1.0.8.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

15/07 2016

v1.0.7

1.0.7.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

15/07 2016

v1.0.6

1.0.6.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

15/07 2016

v1.0.5

1.0.5.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

13/07 2016

v1.0.4

1.0.4.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

12/07 2016

v1.0.3

1.0.3.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

12/07 2016

v1.0.2

1.0.2.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer

08/07 2016
07/07 2016

v1.0.0

1.0.0.0

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Jerome Schaeffer