drupol / drupal7_psr3_watchdog
A PSR3 logger using Drupal 7 watchdog.
Installs: 22 590
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >= 5.6
- psr/log: ^1.0
Requires (Dev)
- drupal/drupal: ^7
- drupol/php-conventions: ^1.5
- drupol/phpspec-code-coverage: ^4
- phpspec/phpspec: ^4
- phptaskman/changelog: ^0.1
- scrutinizer/ocular: ^1.6
Provides
- psr/log-implementation: 1.0.0
README
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