Selective Watchdog Backend

Categories

Component ID

2760833

Component name

Selective Watchdog Backend

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

Tiny module that lets you filter watchdog entries for given backends, based on type and/or severity.
Typical use would be to have all entries logged to syslog for perfomance reasons, but a few ones still logged to database for easier debugging/filtering.

Usage

Enable as usual, and add a $conf['selectlog'] entry to your settings.php file. It must be an array keyed by backend modules (modules implementing hook_watchdog), with values either of log entry types keyed by severity, or severities keyed by types.
You can also use '*' as a catch-all marker.
Example:


$conf['selectlog'] = array(
  'dblog' => array(
    'mycustom_module' => '*',
    WATCHDOG_CRITICAL => '*',
    WATCHDOG_ERROR => array(
      'node',
      'views',
    ),
    'comment' => array(
      WATCHDOG_ALERT,
      WATCHDOG_DEBUG,
      WATCHDOG_EMERGENCY,
    ),
  ),
);

This would results on dblog module logging entries that matches:

  • any entry of type 'mycustom_module'
  • any entries of type WATCHDOG_CRITICAL
  • entries of severity WATCHDOG_ERROR and type 'node' or 'views'
  • entries of type 'comment' and severity of WATCHDOG_ALERT, WATCHDOG_DEBUG or WATCHDOG_EMERGENCY

Any other watchdog backend modules, eg, syslog, would continue to log all
entries as usual.

Notes

  • Some modules are implementing hook_watchdog but are not actual backend loggers, and instead use the hook to react (rules, etc),
  • Enabling the module without any defined $conf['selectlog'] has no effect.
  • Only add entries for modules you want to filter on, leave others apart. Typically, do not include your default backend (syslog, mongodb, …) in the settings array.

Similar modules

Some other modules do provide filtering functionalities eg https://www.drupal.org/project/watchdog_filtering or https://www.drupal.org/sandbox/manarth/1600770
Other watchdog related modules : https://www.drupal.org/search/site/watchdog?f[0]=ss_meta_type%3Amodule
Also checkout core issues #1408208: Enable users to determine which types of log messages get written to syslog. Right now it's all or nothing. and #1295182: Add filtering to dblog before log entries go in.

Why yet another one, then ?

  • backend agnostic
  • small and easy to use and maintain but flexible
  • compatible with core/contrib watchdog() calls
  • usable now for D7