PHPackages                             fei/logger-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. fei/logger-client

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

fei/logger-client
=================

Client side logger

v1.4.2(5y ago)024.9k3GPL-3.0PHPPHP ^7.0

Since Jul 7Pushed 2y ago25 watchersCompare

[ Source](https://github.com/flash-global/logger-client)[ Packagist](https://packagist.org/packages/fei/logger-client)[ RSS](/packages/fei-logger-client/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (6)Dependencies (6)Versions (44)Used By (3)

Logger Client
=============

[](#logger-client)

[![GitHub license](https://camo.githubusercontent.com/91cacdc7f7a5c6bd3b530f9e324e11ccf2e3efc5b27a1975a3ee6498fe0e5b45/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f666c6173682d676c6f62616c2f6c6f676765722d636c69656e742e737667)](https://github.com/flash-global/logger-client)[![continuousphp](https://camo.githubusercontent.com/5d9d7ae672ee40fe7bc87cff6439288596edc95e6c0ce05e7ea43d2bd24eb2cb/68747470733a2f2f696d672e736869656c64732e696f2f636f6e74696e756f75737068702f6769742d6875622f666c6173682d676c6f62616c2f6c6f676765722d636c69656e742e737667)](https://camo.githubusercontent.com/5d9d7ae672ee40fe7bc87cff6439288596edc95e6c0ce05e7ea43d2bd24eb2cb/68747470733a2f2f696d672e736869656c64732e696f2f636f6e74696e756f75737068702f6769742d6875622f666c6173682d676c6f62616c2f6c6f676765722d636c69656e742e737667)[![GitHub issues](https://camo.githubusercontent.com/7b7b806bf0753b1fc9157107c6c24221c8f5220b026d324a5efa787e899d7de6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f666c6173682d676c6f62616c2f6c6f676765722d636c69656e742e737667)](https://github.com/flash-global/logger-client/issues)

Installation
------------

[](#installation)

Just add the following requirement to your `composer.json` file:

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

```

Configuration
-------------

[](#configuration)

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

OptionDescriptionTypePossible ValuesDefaultOPTION\_BASEURLThis is the server to which send the requests.stringAny URL, including protocol but excluding path--OPTION\_FILTERMinimum notification level required for notifications to be actually sent.intAny Notification::LVL\_\* constantNotification::LVL\_ERROROPTION\_BACKTRACEShould backtrace be added to notifications before they are sent.booltrue / falsetrueOPTION\_LOGFILEFile path and name where the Logger will store its own exceptions.stringAny writeable file path/tmp/logger.logOPTION\_HEADER\_AUTHORIZATIONApi Key for authentificationstringAny string value''Notes: *Logger is an alias of Fei\\Service\\Logger\\Client\\Logger**Notification is an alias of Fei\\Service\\Logger\\Entity\\Notification*

Usage
-----

[](#usage)

### Initialization

[](#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.

```
// 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

[](#pushing-a-simple-notification)

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

```
$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.

### Pushing a Notification instance

[](#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:

```
$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-adapter)

PSR-3 describe an interface for logging purpose to ensure interoperability between systems.

For this end we provide the adapter `Fei\Service\Logger\Client\Psr\PsrLoggerAdapter`.

```
