drupol/drupal7_psr3_watchdog

This package is abandoned and no longer maintained. No replacement package was suggested.

A PSR3 logger using Drupal 7 watchdog.

1.1.1 2019-08-11 21:38 UTC

This package is auto-updated.

Last update: 2023-02-12 04:58:32 UTC


README

Build Status

A PSR-3 compatible logger

A very basic PSR-3 compatible logger using Drupal 7 watchdog() function.

Installation

composer require drupol/drupal_psr3_watchdog

Basic usage

function HOOK_init() {
  // Make sure to load the autoload.php, there are multiple way to do that.
  // include_once '/path/to/vendor/autoload.php';

  $logger = new \drupol\drupal7_psr3_watchdog\Logger\WatchdogLogger('Custom');
  
  $logger->alert('This is an alert message.');
  $logger->critical('This is a critical message.');
  $logger->debug('This is a debug message.');
  $logger->emergency('This is an emergency message.');
  $logger->error('This is an error message.');
  $logger->info('This is an info message.');
  $logger->notice('This is a notice message.');
  $logger->warning('This is a warning message.');
  }  

Monolog integration

This library provides a custom handler for Monolog.

Usage with Monolog

  // Make sure to load the autoload.php, there are multiple way to do that.
  // include_once '/path/to/vendor/autoload.php';

  // Create the logger
  $logger = new \Monolog\Logger('Custom');

  // Now add the handler
  $logger->pushHandler(new \drupol\drupal7_psr3_watchdog\Handler\Drupal7Watchdog());

  $logger->alert('This is an alert message.');
  $logger->critical('This is a critical message.');
  $logger->debug('This is a debug message.');
  $logger->emergency('This is an emergency message.');
  $logger->error('This is an error message.');
  $logger->info('This is an info message.');
  $logger->notice('This is a notice message.');
  $logger->warning('This is a warning message.');  
  }

You can also use variable replacements by adding the specific placeholders:

  $logger->alert('This is an {type} message.', array('type' => 'ALERT'));

Drupal's watchdog function also have a 'link' parameter that you can use:

  $logger->warning('This is a {type} message.', array('type' => 'WARNING', 'link' => '<a href="https://github.com/">Github</a>'));

Tests

Test and coverage are provided by PHPSpec.

To run the tests:

composer grumphp