PHPackages                             dwendrich/monolog-config - 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. dwendrich/monolog-config

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

dwendrich/monolog-config
========================

Simply integrate configurable monolog instances via laminas-servicemanager.

2.0.0(4y ago)146MITPHPPHP ^7.1 || &gt;=7.2CI failing

Since Apr 18Pushed 4y agoCompare

[ Source](https://github.com/dwendrich/monolog-config)[ Packagist](https://packagist.org/packages/dwendrich/monolog-config)[ Docs](https://github.com/dwendrich/monolog-config)[ RSS](/packages/dwendrich-monolog-config/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (22)Used By (0)

monolog-config
==============

[](#monolog-config)

Simply integrate configurable monolog instances into applications using laminas-servicemanager.

[![Coverage Status](https://camo.githubusercontent.com/b78c757bf2a2baf131470d762a0dd9d989aae9eb95f21d2e57788f9c49a4418c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6477656e64726963682f6d6f6e6f6c6f672d636f6e6669672e737667)](https://codecov.io/gh/dwendrich/monolog-config)[![Latest Stable Version](https://camo.githubusercontent.com/3dd046f2426ad5356a94802c1a3126d6dfa538fb10b6d68ed20e96c5d15c230a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6477656e64726963682f6d6f6e6f6c6f672d636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/dwendrich/monolog-config)

Based on .

Requirements
------------

[](#requirements)

- monolog-config ^2.0 works with PHP 7.2 or higher, [Monolog 2 or higher](https://www.github.com/Seldaek/monolog)
- for PHP 7.1 support use monolog-config ^1.0
- [Laminas servicemanager component 3.4 or higher](https://docs.laminas.dev/laminas-servicemanager/)

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

[](#installation)

MonologConfig can be installed with composer. For information on how to get composer or how to use it, please refer to [getcomposer.org](http://getcomposer.org).

Installation via command line:

```
$ php composer.phar require dwendrich/monolog-config
```

Installation via `composer.json` file:

```
{
    "require": {
        "dwendrich/monolog-config": "^2.0"
    }
}
```

To enable creation of logger instances through laminas-servicemanager, three factories have to be registered.

As part of a mezzio application, for example, you add `ConfigProvider::class` to `config/config.php`:

```
$aggregator = new ConfigAggregator([

    MonologConfig\ConfigProvider::class,

    // ... other stuff goes here

    // Load application config in a pre-defined order in such a way that local settings
    // overwrite global settings. (Loaded as first to last):
    //   - `global.php`
    //   - `*.global.php`
    //   - `local.php`
    //   - `*.local.php`
    new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),

    // Load development config if it exists
    new PhpFileProvider('config/development.config.php'),
], $cacheConfig['config_cache_path']);
```

In case you implement a laminas mvc application, add `MonologConfig` key to `config/modules.config.php` or the modules section in `config/application.config.php` respectively.

Usage
-----

[](#usage)

### Logger configuration

[](#logger-configuration)

In your application or module configuration simply add a key to the `monolog` section below the `logger` key.

For example, a logger with the key `Application\Log` can be set up like this:

```
return [
    'monolog' => [
        'logger' => [
            'Application\Log' => [
                'channel' => 'default',
            ],
        ],
    ],
];
```

The minimum requirement to define a logger is the `channel` attribute. Channels are used to assign log records to certain parts of the application.

### Handler configuration

[](#handler-configuration)

The logger by itself does not know how to handle log records. This is delegated to one or more handlers. For further information about handlers, formatters and their usage please refer to the [monolog documentation](https://github.com/Seldaek/monolog).

The code below registers two handlers with the logger:

```
return [
    'monolog' => [
        'logger' => [
            'Application\Log' => [
                'channel' => 'default',
                'handlers' => [
                    'stream' => [
                        'class' => \MonologConfig\Handler\RotatingFileSizeHandler::class,
                        'options' => [
                            'filename'    => 'data/log/application.log',
                            'filesize'    => 2.5,
                            'compression' => 9,
                            'level'       => Logger::DEBUG,
                        ],
                    ],
                    'fire_php' => new \Monolog\Handler\FirePHPHandler(),
                ],
            ],
        ],
    ],
];
```

The handler definition has to either be an array containing at least a `class` attribute or an instance of `Monolog\Handler\HandlerInterface`.

### Adding processors

[](#adding-processors)

Processors allow to add extra information to the log record. The following code illustrates how to add processors:

```
return [
    'monolog' => [
        'logger' => [
            'Application\Log' => [
                'channel' => 'default',
                'handlers' => [
                    'stream' => [
                        'class' => StreamHandler::class,
                        'options' => [
                            'path' => 'data/log/application.log',
                            'level' => Logger::DEBUG,
                        ],
                    ],
                ],
                'processors' => [
                    UidProcessor::class,
                    new \Monolog\Processor\IntrospectionProcessor(Logger::ERROR),
                ],
            ],
        ],
    ],
];
```

To add a processor, you can use a string to create an instance or pass an object. Processors have to be callable in order to work with monolog.

### Adding formatters

[](#adding-formatters)

Formatters are used to format the output of a log record. They can be attached to a handler.

```
return [
    'monolog' => [
        'logger' => [
            'Application\Log' => [
                'channel' => 'default',
                'handlers' => [
                    'stream' => [
                        'class' => StreamHandler::class,
                        'options' => [
                            'path' => 'data/log/application.log',
                            'level' => Logger::DEBUG,
                        ],
                        'formatter' => [
                            'class' => LineFormatter::class,
                            'options' => [
                                'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
];
```

A Formatter may be added by providing an array containg a `class` attribute and optionally an `options` key containing constructor parameter.

Alternatively an instance of `Monolog\Formatter\FormatterInterface` can be passed in as argument:

```
return [
    'monolog' => [
        'logger' => [
            'Application\Log' => [
                'channel' => 'default',
                'handlers' => [
                    'stream' => [
                        'class' => StreamHandler::class,
                        'options' => [
                            'path' => 'data/log/application.log',
                            'level' => Logger::DEBUG,
                        ],
                        'formatter' => new LineFormatter(
                            "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
                        ),
                    ],
                ],
            ],
        ],
    ],
];
```

### Retrieving a logger instance

[](#retrieving-a-logger-instance)

You can retrieve a logger instance from laminas-servicemanager by its configuration key, for example:

```
/** @var Laminas\ServiceManager\ServiceManager $container */
$logger = $container->get('Application\Log');
$logger->debug('debug message');
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~90 days

Recently: every ~445 days

Total

21

Last Release

1559d ago

Major Versions

0.3.6 → 1.0.02020-09-01

1.0.1 → 2.0.02022-03-24

PHP version history (4 changes)0.1.0PHP ^5.6 || ^7.0

0.3.0PHP ^7.0

1.0.0PHP ^7.1

2.0.0PHP ^7.1 || &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/27724412?v=4)[Daniel Wendrich](/maintainers/dwendrich)[@dwendrich](https://github.com/dwendrich)

---

Top Contributors

[![dwendrich](https://avatars.githubusercontent.com/u/27724412?v=4)](https://github.com/dwendrich "dwendrich (60 commits)")

---

Tags

loggingmonologphpzend-servicemanagerzendframeworkloglaminasloggermonolog

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dwendrich-monolog-config/health.svg)

```
[![Health](https://phpackages.com/badges/dwendrich-monolog-config/health.svg)](https://phpackages.com/packages/dwendrich-monolog-config)
```

###  Alternatives

[theorchard/monolog-cascade

Monolog extension to configure multiple loggers in the blink of an eye and access them from anywhere

1482.2M9](/packages/theorchard-monolog-cascade)[inpsyde/wonolog

Monolog-based logging package for WordPress.

184631.3k7](/packages/inpsyde-wonolog)[logtail/monolog-logtail

Logtail handler for Monolog

233.5M3](/packages/logtail-monolog-logtail)[bitrix-expert/monolog-adapter

Monolog adapter for Bitrix CMS

6566.6k](/packages/bitrix-expert-monolog-adapter)[glopgar/monolog-timer-processor

A processor for Monolog that adds timing info to the message contexts

1570.3k](/packages/glopgar-monolog-timer-processor)[yzen.dev/mono-processor

This Processor will display in the logs bread crumbs by which you can more quickly and accurately identify the cause of the error.

116.1k](/packages/yzendev-mono-processor)

PHPackages © 2026

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