drupol/drupal7_psr3_watchdog
A PSR3 logger using Drupal 7 watchdog.
1.1.0
2018-01-24 20:08 UTC
Requires
- php: ^5.6 || ^7.0 || ^7.1
- psr/log: ^1.0
Requires (Dev)
- leanphp/phpspec-code-coverage: ^3.1
- phpro/grumphp: ^0.12
- squizlabs/php_codesniffer: ^3.0
- scrutinizer/ocular: ^1.4
- phpmd/phpmd: ^2.6
- sebastian/phpcpd: ^3.0
- sensiolabs/security-checker: ^4.1
- friendsofphp/php-cs-fixer: ^2.7
- drupal/drupal: ^7
- phpspec/phpspec: ^3.4
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 phpspec