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

Abandoned → [drupal/monolog](/?search=drupal%2Fmonolog)Drupal-module[Logging &amp; Monitoring](/categories/logging)

esolitos/monolog
================

A Framework and UI for integrating with the Monolog library.

01.6kPHP

Since Apr 18Pushed 7y ago3 watchersCompare

[ Source](https://github.com/ramsalt/drupal-module-monolog)[ Packagist](https://packagist.org/packages/esolitos/monolog)[ RSS](/packages/esolitos-monolog/feed)WikiDiscussions 8.x-1.x Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Monolog for Drupal 8
====================

[](#monolog-for-drupal-8)

Overview
--------

[](#overview)

This module integrates Drupal with the fantastic [Monolog library by Seldaek](https://github.com/Seldaek/monolog) to provide a better logging solution. Some of the benefits of using this module are as follows:

- Configurable logging levels
- A multitude of handlers
- All the power and flexibility of Monolog

The Drupal Monolog module also has full watchdog integration, so it works with core and contributed modules out of the box.

Monolog sends your logs to files, sockets, inboxes, databases and various web services. This module is a thin wrapper to integrate the Monolog library with the Drupal logging system. For more information on how the Monolog library itself works, take a look to the [documentation](https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md).

Install
-------

[](#install)

The Monolog module needs to be installed via Composer, which will also download the required library. Look at [Using Composer with Drupal](https://www.drupal.org/node/2404989) for further information.

Quick start
===========

[](#quick-start)

Monolog module does not have an UI, all the configuration is done in services files.

You should create a site specific services.yml (monolog.services.yml for example) in the same folder of your settings.php and then add this line to settings.php itself:

```
$settings['container_yamls'][] = 'sites/default/monolog.services.yml';

```

The simplest configuration that allows Monolog to log to a rotating file might be:

```
parameters:
  monolog.channel_handlers:
    default: ['rotating_file']
  monolog.processors: ['message_placeholder', 'current_user', 'request_uri', 'ip', 'referer']

services:
  monolog.handler.rotating_file:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['private://logs/debug.log', 10, 'monolog.level.debug']

```

This configuration will log every message with a log level greater (or equal) than *debug* to a file called *debug.log* located into the *logs* folder in your private filesystem. Files will be rotated every day and the maximum number of files to keep will be *10*.

How it works
============

[](#how-it-works)

Handlers
--------

[](#handlers)

Handlers are registered as services in the [Drupal Service Container](https://www.drupal.org/docs/8/api/services-and-dependency-injection/services-and-dependency-injection-in-drupal-8). You can define as many handlers as you need. Each handler has a name (that should be under the *monolog.handler.* namespace), an implementing class and a list of arguments.

Mapping among logger channels and Monolog handlers is done defining parameters. Under the *monolog.channel\_handlers* parameter it is possible to define where to send logs from a specific channel. The *default* mapping should exist as the fallback one. In the previous example all logs will be sent to the *monolog.handler.rotating\_file* handler (note that only the handler name is used, not the full service name).

The following example will send all PHP specific logs to a separate file:

```
parameters:
  monolog.channel_handlers:
    php: ['rotating_file_php']
    default: ['rotating_file_all']
  monolog.processors: ['message_placeholder', 'current_user', 'request_uri', 'ip', 'referer']

services:
  monolog.handler.rotating_file_php:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['private://logs/php.log', 10, 'monolog.level.debug']
  monolog.handler.rotating_file_all:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['private://logs/debug.log', 10, 'monolog.level.debug']

```

The following method:

```
\Drupal::logger('php')->debug('debug message');

```

will write the corresponding message to the *private://logs/php.log* file.

Processors
----------

[](#processors)

Monolog can alter the messages being written to a logging facility using *processors*. The module provides a set of already defined processors to add information like the current user, the request uri, the client IP and so on.

Processors are defined as services under the *monolog.processor.* namespace. We suggest you to use the [Devel module](https://www.drupal.org/project/devel) or [Drupal Console](https://drupalconsole.com) to find all of them.

Log to database
---------------

[](#log-to-database)

The Monolog module automatically register an handler for every enabled Drupal logger. To log to the standard watchdog table it is possible to enable the Database Logging module and use *drupal.dblog* as handler.

Examples
--------

[](#examples)

- RotatingFileHandler: logs to filesystem

```
  monolog.handler.rotating_file_debug:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['public://logs/debug.log', 10, 'monolog.level.debug']

```

- SlackHandler: logs to a Slack channel

```
  monolog.handler.slack:
    class: Monolog\Handler\SlackHandler
    arguments: ['slack-token', 'monolog', 'Drupal', true, null, 'monolog.level.error']

```

- [FingersCrossedHandler](https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#wrappers--special-handlers)

```
  monolog.handler.fg:
    class: Monolog\Handler\FingersCrossedHandler
    arguments: ['@monolog.handler.slack', null, 100]

```

You can find the complete list of Processors/Handlers [here](https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#handlers).

Extending Monolog
-----------------

[](#extending-monolog)

Handlers and Processors are Drupal/Symfony Services. It is possible to define new ones or alter the existing ones just using Drupal 8 OOP standard approaches.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1de38888940a0d3b94ece87ff411488521f183d1d48dbe0cdb92acd067aa113?d=identicon)[esolitos](/maintainers/esolitos)

---

Top Contributors

[![ParisLiakos](https://avatars.githubusercontent.com/u/656465?v=4)](https://github.com/ParisLiakos "ParisLiakos (19 commits)")[![emmdel](https://avatars.githubusercontent.com/u/249890?v=4)](https://github.com/emmdel "emmdel (1 commits)")[![legolasbo](https://avatars.githubusercontent.com/u/8048544?v=4)](https://github.com/legolasbo "legolasbo (1 commits)")

### Embed Badge

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

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M262](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

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