drupol/drupal7_psr3_watchdog

此软件包已被废弃,不再维护。未建议替代软件包。

使用 Drupal 7 watchdog 的 PSR3 记录器。

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

PSR-3 兼容记录器

一个非常基本的 PSR-3 兼容记录器,使用 Drupal 7 watchdog() 函数

安装

composer require drupol/drupal_psr3_watchdog

基本用法

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 集成

此库为 Monolog 提供了一个自定义处理器。

与 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.');  
  }

您也可以通过添加特定的占位符来使用变量替换

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

Drupal 的 watchdog 函数还有一个可用的 'link' 参数

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

测试

测试和覆盖率由 PHPSpec 提供。

要运行测试

composer grumphp