PHPackages                             eddiejaoude/zf2-logger - 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. eddiejaoude/zf2-logger

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

eddiejaoude/zf2-logger
======================

Zend Framework 2 Logger - request &amp; response log

0.4.1(11y ago)3719.1k16[3 PRs](https://github.com/eddiejaoude/zf2-logger/pulls)MITPHPPHP &gt;=5.4

Since Jan 15Pushed 10y ago3 watchersCompare

[ Source](https://github.com/eddiejaoude/zf2-logger)[ Packagist](https://packagist.org/packages/eddiejaoude/zf2-logger)[ RSS](/packages/eddiejaoude-zf2-logger/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (8)Versions (14)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6d11d0bfca732720dc7f8b5985e6be4fa6a3ed3601749efdd11d3f147d7e8750/68747470733a2f2f7472617669732d63692e6f72672f65646469656a616f7564652f7a66322d6c6f676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/eddiejaoude/zf2-logger)[![Coverage Status](https://camo.githubusercontent.com/7ad9a7cfcb06db906584dcb0522d0ca200b203a582a3ae5f5ae900fd0ac85411/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f65646469656a616f7564652f7a66322d6c6f676765722f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/eddiejaoude/zf2-logger?branch=master)[![Total Downloads](https://camo.githubusercontent.com/80e9a7c885647a8ca596877680d9ccb0d7dbb4a2c32a55dd6b1ee600c630f77b/68747470733a2f2f706f7365722e707567782e6f72672f65646469656a616f7564652f7a66322d6c6f676765722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/eddiejaoude/zf2-logger)[![Dependency Status](https://camo.githubusercontent.com/fbcc7c11f7aa9f721b5471b7170259adadeae2d652f497744eb305af897de624/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3533313937386333656331333735623639633030303966322f62616467652e706e67)](https://www.versioneye.com/user/projects/531978c3ec1375b69c0009f2)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/0e7c8aad561cc6cc439451bf134d2b9b1bb68eb04fa585b1e6ac653bf9cfd7e9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f65646469656a616f7564652f7a66322d6c6f676765722f6261646765732f7175616c6974792d73636f72652e706e673f733d63616635643235643465623739613834653136386366363833366531316163363835313864376338)](https://scrutinizer-ci.com/g/eddiejaoude/zf2-logger/)

[![DashboardHub Badge](https://camo.githubusercontent.com/511b8f6c4b42feb93c28f85546dc0945acdea0438352142f758ed66bc766d347/687474703a2f2f62616467652e64617368626f6172646875622e696f2f62616467652f35353036653765306631653064392e3333383833333637 "DashboardHub Badge")](http://badge.dashboardhub.io/d/5506e7e0f1e0d9.33883367)

EddieJaoude\\Zf2Logger
======================

[](#eddiejaoudezf2logger)

#### Zend Framework 2 Event Logger.

[](#zend-framework-2-event-logger)

- Log incoming Requests &amp; Response data with host name
- Manually log your application information with priorities (i.e. emerg..debug)
- Change your logging output via config without changing code
- Multiple logging outputs (i.e. file(s), stdout, stderr etc)
- Filter errors to log per environment (i.e production &gt; error, development &gt; debug)
- Default log information includes (Session Id, Host, IP)

---

Installation via Composer
-------------------------

[](#installation-via-composer)

### Steps

[](#steps)

#### 1. Add to composer.

[](#1-add-to-composer)

```
    "require" : {
        "eddiejaoude/zf2-logger" : "0.*"
    }

```

Update your dependencies `php composer.phar update eddiejaoude/zf2-logger`

#### 2. Copy the configuration file `config/module.config.php.dist` to `config/autoload/zf2Logger.global.php`

[](#2-copy-the-configuration-file-configmoduleconfigphpdist-to-configautoloadzf2loggerglobalphp)

#### 3. Add module to application config (/config/application.config.php)

[](#3-add-module-to-application-config-configapplicationconfigphp)

```
   //...
   'modules' => array(
        'EddieJaoude\Zf2Logger',
   ),
   //...
```

Then you are good to go. Logging READY! All requests &amp; responses will be logged automatically as `DEBUG`

---

Example usage of manual logging &amp; prority
---------------------------------------------

[](#example-usage-of-manual-logging--prority)

As the `Zend\Log\Logger` is returned from the Service call, one can use the methods:

- emerg // Emergency: system is unusable
- alert // Alert: action must be taken immediately
- crit // Critical: critical conditions
- err // Error: error conditions
- warn // Warning: warning conditions
- notice // Notice: normal but significant condition
- info // Informational: informational messages
- debug // Debug: debug messages

```
    //...
    $serviceLocator->get('EddieJaoude\Zf2Logger')->emerg('Emergency message');
    //...
```

### Use an alias for decoupling

[](#use-an-alias-for-decoupling)

Instead of using `EddieJaoude\Zf2Logger` in your code, put an `Alias` in your service manager, therefore allowing you to swap out different logger libraries later on without modifying your code &amp; usage.

i.e.

```
    //...
    'aliases'    => array(
        // alias used, so can be swapped out later without changing any code
        'Logger' => 'EddieJaoude\Zf2Logger'
    ),
    //...

```

Then your usage in your code becomes...

```
    //...
    $serviceLocator->get('Logger')->emerg('Emergency message');
    //...
```

### Add to default logging parameters

[](#add-to-default-logging-parameters)

Additional default logging information includes:

- IP
- Host
- Session Id

To log more additional default information, use `$logger->addCustomExtra($extraArray)`. Full example below.

1. Change the `alias` to your new service *(point 2 below)*i.e.

```
    'aliases' => array(
        // ...
        'Logger' => 'Zf2Logger',
        // ...
    ),
```

2. Create your new service

```
    // ...
    'Zf2Logger' => function($sm) {
        $logger = $sm->get('EddieJaoude\Zf2Logger');
        $logger->addCustomExtra(
            array(
                'host' => !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'CLI',
            )
        );

        return $logger;
    },
    // ...
```

---

Example - built in logging
--------------------------

[](#example---built-in-logging)

Each output includes &amp; is prepended with the host - this is especially useful when working with multi layer/tier architecture, i.e. F/E (UI) -&gt; B/E (API). As these can all write to the same output in the stack execution order or alternatively to different outputs.

### Request (priority DEBUG)

[](#request-priority-debug)

```
    2014-01-09T16:28:23+00:00 DEBUG (7): Array
    (
        [zf2.local] => Array
            (
                [Request] => Zend\Uri\Http Object
                    (
                        [validHostTypes:protected] => 19
                        [user:protected] =>
                        [password:protected] =>
                        [scheme:protected] => http
                        [userInfo:protected] =>
                        [host:protected] => zf2.local
                        [port:protected] =>
                        [path:protected] => /api/user
                        [query:protected] =>
                        [fragment:protected] =>
                    )

            )

    )

```

### Response (priority DEBUG)

[](#response-priority-debug)

```
    2014-01-09T16:28:24+00:00 DEBUG (7): Array
    (
        [zf2.local] => Array
            (
                [Response] => Array
                    (
                        [statusCode] => 200
                        [content] => {"total":2,"data":[{"id":"12345 ...
                        ...
                    )
            )
    )

```

---

Configuration (config)
----------------------

[](#configuration-config)

```
    return array(
        'EddieJaoude\Zf2Logger' => array(

            // will add the $logger object before the current PHP error handler
            'registerErrorHandler'     => 'true', // errors logged to your writers
            'registerExceptionHandler' => 'true', // exceptions logged to your writers

            // do not log binary responses
            // mime types reference http://www.sitepoint.com/web-foundations/mime-types-complete-list/
            'doNotLog'                 => array(
                'mediaTypes' => array(
                    'application/octet-stream',
                    'image/png',
                    'image/jpeg',
                    'application/pdf'
                ),
            ),

            // multiple zend writer output & zend priority filters
            'writers' => array(
                'standard-file' => array(
                    'adapter'  => '\Zend\Log\Writer\Stream',
                    'options'  => array(
                        'output' => 'data/application.log', // path to file
                    ),
                    // options: EMERG, ALERT, CRIT, ERR, WARN, NOTICE, INFO, DEBUG
                    'filter' => \Zend\Log\Logger::DEBUG,
                    'enabled' => true
                ),
                'tmp-file' => array(
                    'adapter'  => '\Zend\Log\Writer\Stream',
                    'options'  => array(
                        'output' => '/tmp/application-' . $_SERVER['SERVER_NAME'] . '.log', // path to file
                    ),
                    // options: EMERG, ALERT, CRIT, ERR, WARN, NOTICE, INFO, DEBUG
                    'filter' => \Zend\Log\Logger::DEBUG,
                    'enabled' => false
                ),
                'standard-output' => array(
                    'adapter'  => '\Zend\Log\Writer\Stream',
                    'options'  => array(
                        'output' => 'php://output'
                    ),
                    // options: EMERG, ALERT, CRIT, ERR, WARN, NOTICE, INFO, DEBUG
                    'filter' => \Zend\Log\Logger::NOTICE,
                    'enabled' => $_SERVER['APPLICATION_ENV'] == 'development' ? true : false
                ),
                'standard-error' => array(
                    'adapter'  => '\Zend\Log\Writer\Stream',
                    'options'  => array(
                        'output' => 'php://stderr'
                    ),
                    // options: EMERG, ALERT, CRIT, ERR, WARN, NOTICE, INFO, DEBUG
                    'filter' => \Zend\Log\Logger::NOTICE,
                    'enabled' => true
                )
            )
        )
    );
```

---

Unit tests
----------

[](#unit-tests)

To run unit tests (from root diectory)

1. Download Composer

```
curl -sS https://getcomposer.org/installer | php

```

2. Install dependencies

```
php composer.phar install

```

3. Run tests

```
vendor/bin/phpunit -c tests/phpunit.xml

```

---

Example output of Log file
--------------------------

[](#example-output-of-log-file)

```
2014-05-08T19:46:43+01:00 DEBUG (7): Array
(
    [zf2.be.local] => Array
        (
            [Request] => Zend\Uri\Http Object
                (
                    [validHostTypes:protected] => 19
                    [user:protected] =>
                    [password:protected] =>
                    [scheme:protected] => http
                    [userInfo:protected] =>
                    [host:protected] => zf2.local
                    [port:protected] => 8080
                    [path:protected] => /api/ddc
                    [query:protected] =>
                    [fragment:protected] =>
                )

        )

)

2014-05-08T19:46:43+01:00 DEBUG (7): Authorisation Check
Role: System Admin
Resource: api-ddc
Method: post
IsAllowed: 1

2014-05-08T19:46:43+01:00 DEBUG (7): Authorisation Check
Role: OPG User
Resource: api-ddc
Method: post
IsAllowed:

2014-05-08T19:46:43+01:00 INFO (6): Import: Starting...
2014-05-08T19:46:43+01:00 INFO (6): Import: Loaded XML (SET.xsd).
2014-05-08T19:46:43+01:00 INFO (6): Import: Found XSD SET.xsd (module/Ddc/src/Ddc/Validator/SET.xsd)
2014-05-08T19:46:43+01:00 INFO (6): Import: Validated XML (SET.xsd).
2014-05-08T19:46:43+01:00 INFO (6): Import: Loaded XML (LPA002.xsd).
2014-05-08T19:46:43+01:00 INFO (6): Import: Found XSD LPA002.xsd (module/Ddc/src/Ddc/Validator/LPA002.xsd)
2014-05-08T19:46:43+01:00 INFO (6): Import: Validated XML (LPA002.xsd).
2014-05-08T19:46:43+01:00 INFO (6): Import: Failed. 'P1 DOB' was not in the expected format d/m/Y H:i:s
2014-05-08T19:46:43+01:00 DEBUG (7): Array
(
    [zf2.local] => Array
        (
            [Response] => Array
                (
                    [statusCode] => 400
                    [content] => {"data":{"success":false},"additionalData":null}
                )

        )

)

```

---

What Next...
------------

[](#what-next)

- Additional events

Ideas &amp; requirements welcome.

---

Contributing
------------

[](#contributing)

- Discussions from Ideas &amp; Discussions to Pull Requests
- Pull requests with Unit tests

---

Resources
---------

[](#resources)

- Github
- Packagist
- Zend Framework 2 Modules
- Travis CI
- Coveralls
- Scrutinizer

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~55 days

Total

12

Last Release

4164d ago

PHP version history (3 changes)v0.1PHP &gt;=5.5

0.3.3PHP &gt;=5.4

0.5.0-rc1PHP &gt;=5.3.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/72a84aeb80493e050ede01d5b15020ecfe55681e8d54ab5f0f68f058326f950b?d=identicon)[eddiejaoude](/maintainers/eddiejaoude)

---

Top Contributors

[![eddiejaoude](https://avatars.githubusercontent.com/u/624760?v=4)](https://github.com/eddiejaoude "eddiejaoude (156 commits)")[![acelaya](https://avatars.githubusercontent.com/u/2719332?v=4)](https://github.com/acelaya "acelaya (4 commits)")[![Perfect-Web](https://avatars.githubusercontent.com/u/1730020?v=4)](https://github.com/Perfect-Web "Perfect-Web (3 commits)")[![brettminnie](https://avatars.githubusercontent.com/u/6124248?v=4)](https://github.com/brettminnie "brettminnie (1 commits)")[![jeremyquinton](https://avatars.githubusercontent.com/u/1847770?v=4)](https://github.com/jeremyquinton "jeremyquinton (1 commits)")

---

Tags

logzendloggerzf2zend framework 2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eddiejaoude-zf2-logger/health.svg)

```
[![Health](https://phpackages.com/badges/eddiejaoude-zf2-logger/health.svg)](https://phpackages.com/packages/eddiejaoude-zf2-logger)
```

###  Alternatives

[snapshotpl/zf-snap-php-debug-bar

PHP Debug Bar module for Zend Framework 2

3026.1k](/packages/snapshotpl-zf-snap-php-debug-bar)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[davidhavl/dherrorlogging

Full featured error logging module for ZF2/ZF3 application

1924.5k](/packages/davidhavl-dherrorlogging)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[amphp/log

Non-blocking logging for PHP based on Amp, Revolt, and Monolog.

402.6M70](/packages/amphp-log)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
