2017 © Pedro Peláez
 

library drupal7_psr3_watchdog

A PSR3 logger using Drupal 7 watchdog.

image

drupol/drupal7_psr3_watchdog

A PSR3 logger using Drupal 7 watchdog.

  • Wednesday, January 24, 2018
  • by drupol
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4,191 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 60 % Grown

The README.md

Build Status, (*1)

A PSR-3 compatible logger

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

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., (*3)

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:, (*4)

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

Drupal's watchdog function also have a 'link' parameter that you can use:, (*5)

  $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., (*6)

To run the tests:, (*7)

composer grumphp

The Versions