From 7d09f18220777f9759b98933bce04ffd461ffc8b Mon Sep 17 00:00:00 2001 From: Frederic G. MARAND Date: Wed, 13 Jun 2012 11:36:46 +0200 Subject: [PATCH 2/2] Initial version: ugly, but works - uses drupal_static to keep loggers, should use the DIC - strange mix of current dblog functionality and class code --- core/includes/bootstrap.inc | 18 ++++++++++++- core/lib/Drupal/Core/Watchdog/Logger.php | 28 ++++++++++++++++++++ .../watchdog/lib/Drupal/watchdog/DbHandler.php | 6 +--- core/modules/watchdog/watchdog.module | 1 - core/vendor/composer/autoload_namespaces.php | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 core/lib/Drupal/Core/Watchdog/Logger.php diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e26cb36..2b6b832 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Exception\RuntimeException as DependencyInjectionRuntimeException; use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Language\Language; +use Drupal\Core\Watchdog\Logger; /** * @file @@ -296,6 +297,13 @@ const REGISTRY_RESET_LOOKUP_CACHE = 1; const REGISTRY_WRITE_LOOKUP_CACHE = 2; /** + * The key in the DI container giving access to the logger instance. + * + * @var string + */ +const WATCHDOG_SERVICE = 'watchdog'; + +/** * Regular expression to match PHP function names. * * @see http://php.net/manual/language.functions.php @@ -1696,7 +1704,12 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { global $user, $base_root; - static $in_error_state = FALSE; + $logger = &drupal_static(__FUNCTION__); + if (!isset($logger)) { + $logger = drupal_container()->set(WATCHDOG_SERVICE, 'Monolog\\Logger'); + } + + $in_error_state = FALSE; // It is possible that the error handling will itself trigger an error. In that case, we could // end up in an infinite loop. To avoid that, we implement a simple static semaphore. @@ -2263,6 +2276,9 @@ function _drupal_bootstrap_configuration() { // Load the procedural configuration system helper functions. require_once DRUPAL_ROOT . '/core/includes/config.inc'; + // Initialize the base Logger for code not using watchdog(). + drupal_container()->register(WATCHDOG_SERVICE, 'Monolog\\Logger') + ->addArgument('channel'); } /** diff --git a/core/lib/Drupal/Core/Watchdog/Logger.php b/core/lib/Drupal/Core/Watchdog/Logger.php new file mode 100644 index 0000000..d5eea47 --- /dev/null +++ b/core/lib/Drupal/Core/Watchdog/Logger.php @@ -0,0 +1,28 @@ +register(WATCHDOG_CONTAINER_KEY, 'Drupal\\Core\\Watchdog\\Logger'); + } +} diff --git a/core/modules/watchdog/lib/Drupal/watchdog/DbHandler.php b/core/modules/watchdog/lib/Drupal/watchdog/DbHandler.php index 0296c2c..1223844 100644 --- a/core/modules/watchdog/lib/Drupal/watchdog/DbHandler.php +++ b/core/modules/watchdog/lib/Drupal/watchdog/DbHandler.php @@ -7,7 +7,6 @@ namespace Drupal\watchdog; - use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Monolog\Handler\AbstractProcessingHandler; @@ -24,8 +23,7 @@ class DbHandler extends AbstractProcessingHandler { * @var \Connection */ protected $db; - /** - */ + function __construct(Connection $connection = NULL, $level = Logger::DEBUG, $bubble = TRUE) { parent::__construct($level, $bubble); $this->db = $connection ?: Database::getConnection(); @@ -64,8 +62,6 @@ class DbHandler extends AbstractProcessingHandler { ->execute(); } - /** - */ function __destruct() { unset($this->db); parent::__destruct(); diff --git a/core/modules/watchdog/watchdog.module b/core/modules/watchdog/watchdog.module index 99a15a0..2f8fb4f 100644 --- a/core/modules/watchdog/watchdog.module +++ b/core/modules/watchdog/watchdog.module @@ -81,7 +81,6 @@ function watchdog_init() { function watchdog_cron() { } - /** * Implements hook_watchdog(). */ diff --git a/core/vendor/composer/autoload_namespaces.php b/core/vendor/composer/autoload_namespaces.php index f3cf2d6..73273cc 100644 --- a/core/vendor/composer/autoload_namespaces.php +++ b/core/vendor/composer/autoload_namespaces.php @@ -16,4 +16,5 @@ return array( 'Symfony\\Component\\ClassLoader' => $vendorDir . '/symfony/class-loader/', 'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs', 'Doctrine\\Common' => $vendorDir . '/doctrine/common/lib/', + 'Monolog' => $vendorDir . 'src', ); -- 1.7.4.1