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
  • Different behaviors per channel via "logging profiles"
  • 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.

Drupal 7

Installation

Follow the standard module installation guide to install the Monolog module. This module depends on the Composer Manager module, so follow the instructions on its project page to install the required third-party libraries.

Usage

It is important to be familiar with the core concepts of Monolog before attempting to use this module.

The quickest way to get started is to enable both the Monolog and Monolog Logging modules so that all messages added via the watchdog system are routed through the Monolog library. After enabling the modules, visit admin/config/development/monolog and select which logging profile is associated with the "Watchdog" channel. Optionally edit the logging profile to configure which handlers will process the records.

Implemented Handlers

The handlers below are made available by this module:

  • Stream Handler (Most common use case is logging to files)
  • Rotating File Handler
  • Syslog Handler
  • Native Mail Handler
  • ChromePHP Handler
  • FirePHP Handler
  • Socket Handler
  • HipChat Handler
  • GELF Handler
  • Null handler

Maintainers

Monolog 7.x is maintained by Chris Pliakas, sponsored by Acquia, and developed by the community.

Drupal 8

Installation

The monolog library is the only requirement and can be installed either by using composer directly or the Composer Manager module.

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: Monolog\Handler\BrowserConsoleHandler
    # Set alert as the minimum level (ignores emergency) and disable bubbling for this Handler
    arguments: ['1', false]

You can also read the blog post by @lussoluca:
www.wellnet.it/en/blog/logging-drupal-8

Project information

Downloads