diff --git a/memcache.module b/memcache.module index 92f76a3..e5009d0 100644 --- a/memcache.module +++ b/memcache.module @@ -1,6 +1,22 @@ log($level, $message, $context); +} diff --git a/src/DrupalMemcache.php b/src/DrupalMemcache.php index 583ad8e..2955a31 100644 --- a/src/DrupalMemcache.php +++ b/src/DrupalMemcache.php @@ -8,6 +8,7 @@ namespace Drupal\memcache; use Drupal\Core\Site\Settings; +use Psr\Log\LogLevel; /** * Class DrupalMemcache. @@ -79,14 +80,17 @@ class DrupalMemcache extends DrupalMemcacheBase { $full_keys[$cid] = $full_key; } - ini_set('track_errors', 1); - $error = ''; + $track_errors = ini_set('track_errors', 1); + $php_errormsg = ''; $results = @$this->memcache->get($full_keys); - if (!empty($error)) { - register_shutdown_function('watchdog', 'memcache', 'Exception caught in DrupalMemcache::getMulti: !msg', array('!msg' => $error), WATCHDOG_WARNING); + if (!empty($php_errormsg) && is_callable('memcache_log_warning')) { + register_shutdown_function('memcache_log_warning', LogLevel::WARNING, 'Exception caught in DrupalMemcache::getMulti: !msg', array('!msg' => $php_errormsg)); + $php_errormsg = ''; } + ini_set('track_errors', $track_errors); + // If $results is FALSE, convert it to an empty array. if (!$results) { $results = array(); diff --git a/src/DrupalMemcacheBase.php b/src/DrupalMemcacheBase.php index f374b99..9b3ba8b 100644 --- a/src/DrupalMemcacheBase.php +++ b/src/DrupalMemcacheBase.php @@ -8,6 +8,7 @@ namespace Drupal\memcache; use Drupal\Core\Site\Settings; +use Psr\Log\LogLevel; /** * Class DrupalMemcacheBase. @@ -64,13 +65,15 @@ abstract class DrupalMemcacheBase implements DrupalMemcacheInterface { public function get($key) { $full_key = $this->key($key); - ini_set('track_errors', '1'); - $error = ''; + $track_errors = ini_set('track_errors', '1'); + $php_errormsg = ''; $result = @$this->memcache->get($full_key); - if (!empty($error)) { - register_shutdown_function('watchdog', 'memcache', 'Exception caught in DrupalMemcache::get !msg', array('!msg' => $error), WATCHDOG_WARNING); + if (!empty($php_errormsg) && is_callable('memcache_log_warning')) { + register_shutdown_function('memcache_log_warning', LogLevel::WARNING, 'Exception caught in DrupalMemcacheBase::get: !msg', array('!msg' => $php_errormsg)); + $php_errormsg = ''; } + ini_set('track_errors', $track_errors); return $result; } diff --git a/src/DrupalMemcacheFactory.php b/src/DrupalMemcacheFactory.php index 47b1b68..91bcfdc 100644 --- a/src/DrupalMemcacheFactory.php +++ b/src/DrupalMemcacheFactory.php @@ -8,6 +8,7 @@ namespace Drupal\memcache; use Drupal\Core\Site\Settings; +use Psr\Log\LogLevel; /** * Factory class for creation of Memcache objects. @@ -113,7 +114,7 @@ class DrupalMemcacheFactory { // We can't use watchdog because this happens in a bootstrap phase // where watchdog is non-functional. Register a shutdown handler // instead so it gets recorded at the end of page load. - register_shutdown_function('watchdog', 'memcache', 'Failed to connect to memcache server: !server', array('!server' => $s), WATCHDOG_ERROR); + register_shutdown_function('memcache_log_warning', LogLevel::ERROR, 'Failed to connect to memcache server: !server', array('!server' => $s)); $this->failedConnectionCache[$s] = FALSE; } } diff --git a/src/DrupalMemcacheInterface.php b/src/DrupalMemcacheInterface.php index 7a14ef2..a945a30 100644 --- a/src/DrupalMemcacheInterface.php +++ b/src/DrupalMemcacheInterface.php @@ -99,5 +99,4 @@ interface DrupalMemcacheInterface { * Whether this server connection is persistent or not. */ public function addServer($server_path, $persistent = FALSE); - } diff --git a/src/MemcacheBackendFactory.php b/src/MemcacheBackendFactory.php index 7327459..3803e10 100644 --- a/src/MemcacheBackendFactory.php +++ b/src/MemcacheBackendFactory.php @@ -40,7 +40,6 @@ class MemcacheBackendFactory { * Constructs the DatabaseBackendFactory object. * * @param \Drupal\Core\Lock\LockBackendInterface $lock - * @param \Drupal\Core\Config\ConfigFactory $config_factory * @param \Drupal\Core\Site\Settings $settings * @param \Drupal\memcache\DrupalMemcacheFactory $memcache_factory */