From 40ce9babdbe798e79b764d61918af0182354e1af Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 13 Sep 2012 11:44:45 -0400 Subject: [PATCH] Set up Summon connection to use dependency injection for logging; improved log output; expanded some comments. --- .../VuFind/src/VuFind/Connection/Summon.php | 41 +++++++++++++------ .../src/VuFind/Search/Summon/Results.php | 1 + 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/module/VuFind/src/VuFind/Connection/Summon.php b/module/VuFind/src/VuFind/Connection/Summon.php index 199aeb39117..c314ce6b5ce 100644 --- a/module/VuFind/src/VuFind/Connection/Summon.php +++ b/module/VuFind/src/VuFind/Connection/Summon.php @@ -28,10 +28,8 @@ */ namespace VuFind\Connection; use SerialsSolutions\Summon\Zend2 as BaseSummon, - VuFind\Config\Reader as ConfigReader, - VuFind\Http\Client as HttpClient, - VuFind\Log\Logger, - VuFind\Solr\Utils as SolrUtils; + VuFind\Config\Reader as ConfigReader, VuFind\Http\Client as HttpClient, + VuFind\Solr\Utils as SolrUtils, Zend\Log\Logger; /** * Summon Search API Interface (VuFind implementation) @@ -48,15 +46,25 @@ class Summon extends BaseSummon /** * Should boolean operators in the search string be treated as * case-insensitive (false), or must they be ALL UPPERCASE (true)? + * + * @var bool */ protected $caseSensitiveBooleans = true; /** * Will we include snippets in responses? + * * @var bool */ protected $snippets = false; + /** + * Logger object for debug info (or false for no debugging). + * + * @var Logger|bool + */ + protected $logger = false; + /** * Constructor * @@ -91,12 +99,6 @@ class Summon extends BaseSummon $this->snippets = $config->General->snippets; } - // Set default debug behavior: - $this->logger = Logger::getInstance(); - if (!isset($options['debug'])) { - $options['debug'] = $this->logger->debugNeeded(); - } - $timeout = isset($config->General->timeout) ? $config->General->timeout : 30; parent::__construct( @@ -106,6 +108,21 @@ class Summon extends BaseSummon ); } + /** + * Set the logger + * + * @param Logger $logger Logger to use. + * + * @return void + */ + public function setLogger(Logger $logger) + { + // Adjust debug property based on logger settings: + $this->debug = method_exists($logger, 'debugNeeded') + ? $logger->debugNeeded() : true; + $this->logger = $logger; + } + /** * Print a message if debug is enabled. * @@ -115,8 +132,8 @@ class Summon extends BaseSummon */ protected function debugPrint($msg) { - if ($this->debug) { - $this->logger->debug("<pre>{$msg}</pre>\n"); + if ($this->debug && $this->logger) { + $this->logger->debug("$msg\n"); } } diff --git a/module/VuFind/src/VuFind/Search/Summon/Results.php b/module/VuFind/src/VuFind/Search/Summon/Results.php index b1637af9534..9441aca8804 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Results.php +++ b/module/VuFind/src/VuFind/Search/Summon/Results.php @@ -60,6 +60,7 @@ class Results extends BaseResults $id = isset($config->Summon->apiId) ? $config->Summon->apiId : null; $key = isset($config->Summon->apiKey) ? $config->Summon->apiKey : null; $conn = new SummonConnection($id, $key); + $conn->setLogger(\VuFind\Log\Logger::getInstance()); } return $conn; } -- GitLab