Monolog

Component ID

1937716

Component name

Monolog

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

34820

Component created

Component changed

Component body

Overview

This module integrates Drupal with the fantastic Monolog library by Seldaek 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 Monolog module also has full watchdog integration, so it works with core and contributed modules out of the box.

Installation

The monolog library is the only requirement and can be installed by using composer.

Usage

In the Drupal 8 version, monolog is configurable through container parameters.
You can specify handlers per channel in your site specific services.yml file. eg:

parameters:
  monolog.channel_handlers:
    # Log to the syslog by default.
    default: ['syslog']
    # Send the php channel to web server's error log and the browser console:
    php: ['error_log', 'browser_console']
    # Ignore log entries of "content" channel.
    content: ['null']

or configuring processors:

parameters:
  # Show memory usage on each log entry:
  monolog.processors: ['message_placeholder', 'current_user', 'request_uri', 'ip', 'referer', 'memory_usage']

Changing levels and bubling for handlers is done by changing the service definition:

services:
  monolog.handler.browser_console:
    class: MonologHandlerBrowserConsoleHandler
    # Set alert as the minimum level (ignores emergency) and disable bubbling for this Handler
    arguments: ['1', false]