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