diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index 0f6a405449f789585f146034ae69dd04859f9869..f69bc00e914fad32a7b434c76c2c0f16f95597d7 100644 --- a/module/VuFind/src/VuFind/Auth/AbstractBase.php +++ b/module/VuFind/src/VuFind/Auth/AbstractBase.php @@ -28,7 +28,6 @@ */ namespace VuFind\Auth; use VuFind\Db\Row\User, VuFind\Exception\Auth as AuthException; -use Zend\Log\LoggerInterface; /** * Abstract authentication base class @@ -45,6 +44,7 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, { use \VuFind\Db\Table\DbTableAwareTrait; use \VuFind\I18n\Translator\TranslatorAwareTrait; + use \VuFind\Log\LoggerAwareTrait; /** * Has the configuration been validated? @@ -60,39 +60,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, */ protected $config = null; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Get configuration (load automatically if not previously set). Throw an * exception if the configuration is invalid. diff --git a/module/VuFind/src/VuFind/Auth/LDAP.php b/module/VuFind/src/VuFind/Auth/LDAP.php index 93e606b88f6942033729285a7c2c5745e686faa1..3dd881635d8a58cc2c427b2672f45ad1dc321985 100644 --- a/module/VuFind/src/VuFind/Auth/LDAP.php +++ b/module/VuFind/src/VuFind/Auth/LDAP.php @@ -126,7 +126,7 @@ class LDAP extends AbstractBase return $this->processLDAPUser($username, $data); } } else { - $this->debug('LDAP: user not found'); + $this->debug('user not found'); } throw new AuthException('authentication_error_invalid'); @@ -145,25 +145,25 @@ class LDAP extends AbstractBase // time! $host = $this->getSetting('host'); $port = $this->getSetting('port'); - $this->debug("LDAP: connecting to host=$host, port=$port"); + $this->debug("connecting to host=$host, port=$port"); $connection = @ldap_connect($host, $port); if (!$connection) { - $this->debug('LDAP: connection failed'); + $this->debug('connection failed'); throw new AuthException('authentication_error_technical'); } // Set LDAP options -- use protocol version 3 if (!@ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3)) { - $this->debug('LDAP: Failed to set protocol version 3'); + $this->debug('Failed to set protocol version 3'); } // if the host parameter is not specified as ldaps:// // then we need to initiate TLS so we // can have a secure connection over the standard LDAP port. if (stripos($host, 'ldaps://') === false) { - $this->debug('LDAP: Starting TLS'); + $this->debug('Starting TLS'); if (!@ldap_start_tls($connection)) { - $this->debug('LDAP: TLS failed'); + $this->debug('TLS failed'); throw new AuthException('authentication_error_technical'); } } @@ -186,10 +186,10 @@ class LDAP extends AbstractBase $user = $this->getSetting('bind_username'); $pass = $this->getSetting('bind_password'); if ($user != '' && $pass != '') { - $this->debug("LDAP: binding as $user"); + $this->debug("binding as $user"); $ldapBind = @ldap_bind($connection, $user, $pass); if (!$ldapBind) { - $this->debug('LDAP: bind failed -- ' . ldap_error($connection)); + $this->debug('bind failed -- ' . ldap_error($connection)); throw new AuthException('authentication_error_technical'); } } @@ -207,10 +207,10 @@ class LDAP extends AbstractBase { $ldapFilter = $this->getSetting('username') . '=' . $username; $basedn = $this->getSetting('basedn'); - $this->debug("LDAP: search for $ldapFilter using basedn=$basedn"); + $this->debug("search for $ldapFilter using basedn=$basedn"); $ldapSearch = @ldap_search($connection, $basedn, $ldapFilter); if (!$ldapSearch) { - $this->debug('LDAP: search failed -- ' . ldap_error($connection)); + $this->debug('search failed -- ' . ldap_error($connection)); throw new AuthException('authentication_error_technical'); } @@ -230,18 +230,18 @@ class LDAP extends AbstractBase { // Validate the user credentials by attempting to bind to LDAP: $dn = $info[0]['dn']; - $this->debug("LDAP: binding as $dn"); + $this->debug("binding as $dn"); $ldapBind = @ldap_bind($connection, $dn, $password); if (!$ldapBind) { - $this->debug('LDAP: bind failed -- ' . ldap_error($connection)); + $this->debug('bind failed -- ' . ldap_error($connection)); return false; } // If the bind was successful, we can look up the full user info: - $this->debug('LDAP: bind successful; reading details'); + $this->debug('bind successful; reading details'); $ldapSearch = ldap_read($connection, $dn, 'objectclass=*'); $data = ldap_get_entries($connection, $ldapSearch); if ($data === false) { - $this->debug('LDAP: Read failed -- ' . ldap_error($connection)); + $this->debug('Read failed -- ' . ldap_error($connection)); throw new AuthException('authentication_error_technical'); } return $data; @@ -278,7 +278,7 @@ class LDAP extends AbstractBase $configValue = $this->getSetting($field); if ($data[$i][$j] == $configValue && !empty($configValue)) { $value = $data[$i][$configValue][0]; - $this->debug("LDAP: found $field = $value"); + $this->debug("found $field = $value"); if ($field != "cat_password" ) { $user->$field = $value; } else { diff --git a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php index 967e744fe2f1e6b228dfbfdf39191244d054c463..15e886ce1c8654169742df04686d482dc2d15c00 100644 --- a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php +++ b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php @@ -26,8 +26,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ namespace VuFind\Connection; -use File_MARCXML, VuFind\XSLT\Processor as XSLTProcessor, Zend\Config\Config, - Zend\Log\LoggerInterface; +use File_MARCXML, VuFind\XSLT\Processor as XSLTProcessor, Zend\Config\Config; /** * World Cat Utilities @@ -42,12 +41,7 @@ use File_MARCXML, VuFind\XSLT\Processor as XSLTProcessor, Zend\Config\Config, */ class WorldCatUtils implements \Zend\Log\LoggerAwareInterface { - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; + use \VuFind\Log\LoggerAwareTrait; /** * WorldCat configuration @@ -100,32 +94,6 @@ class WorldCatUtils implements \Zend\Log\LoggerAwareInterface $this->ip = $ip; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Retrieve data over HTTP. * diff --git a/module/VuFind/src/VuFind/Content/AbstractBase.php b/module/VuFind/src/VuFind/Content/AbstractBase.php index ac621ecd00b982c992c83eecd19b78eae51957d2..63fc1d414b0f69cb307fab474faf1ce361ee6124 100644 --- a/module/VuFind/src/VuFind/Content/AbstractBase.php +++ b/module/VuFind/src/VuFind/Content/AbstractBase.php @@ -40,27 +40,9 @@ use VuFindCode\ISBN; abstract class AbstractBase implements \VuFindHttp\HttpServiceAwareInterface, \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; use \VuFindHttp\HttpServiceAwareTrait; - /** - * Logger - * - * @var \Zend\Log\LoggerInterface|bool - */ - protected $logger = false; - - /** - * Set logger - * - * @param \Zend\Log\LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(\Zend\Log\LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Attempt to get an ISBN-10; revert to ISBN-13 only when ISBN-10 representation * is impossible. diff --git a/module/VuFind/src/VuFind/Content/AbstractSyndetics.php b/module/VuFind/src/VuFind/Content/AbstractSyndetics.php index 8ba8431c1fac103733497b0a97b0460ae8d65511..e1d4a8b85a940957824b2687e0a5f84a0b4a85d9 100644 --- a/module/VuFind/src/VuFind/Content/AbstractSyndetics.php +++ b/module/VuFind/src/VuFind/Content/AbstractSyndetics.php @@ -105,9 +105,7 @@ abstract class AbstractSyndetics extends AbstractBase ? 'https://secure.syndetics.com' : 'http://syndetics.com'; $url = $baseUrl . '/index.aspx?isbn=' . $isbn . '/' . $file . '&client=' . $id . '&type=' . $type; - if ($this->logger) { - $this->logger->debug('Syndetics request: ' . $url); - } + $this->debug('Syndetics request: ' . $url); return $url; } diff --git a/module/VuFind/src/VuFind/Content/Reviews/Booksite.php b/module/VuFind/src/VuFind/Content/Reviews/Booksite.php index 2988f97b6aa9779f50fe00fc2156384f96e23709..49f009b8cc881cebc41d88ed1cf9b8bc077f9fb0 100644 --- a/module/VuFind/src/VuFind/Content/Reviews/Booksite.php +++ b/module/VuFind/src/VuFind/Content/Reviews/Booksite.php @@ -86,20 +86,16 @@ class BookSite extends \VuFind\Content\AbstractBase . '&ean=' . $isn; $response = $this->getHttpClient($url)->send(); if (!$response->isSuccess()) { - if ($this->logger) { - $this->logger->warn( - "Reviews: " . $response->getStatusCode() . " " - . $response->getReasonPhrase() . " $url" - ); - } - return $reviews; // still empty - } - if ($this->logger) { - $this->logger->debug( + $this->logWarning( "Reviews: " . $response->getStatusCode() . " " . $response->getReasonPhrase() . " $url" ); + return $reviews; // still empty } + $this->debug( + "Reviews: " . $response->getStatusCode() . " " + . $response->getReasonPhrase() . " $url" + ); $i = 0; $json = json_decode($response->getBody()); diff --git a/module/VuFind/src/VuFind/Content/Reviews/Guardian.php b/module/VuFind/src/VuFind/Content/Reviews/Guardian.php index 09dc05add430e626a9fd5bf93d30acbf379cf80d..39d918f4f66113c34da1436936bcda4d1ee234d7 100644 --- a/module/VuFind/src/VuFind/Content/Reviews/Guardian.php +++ b/module/VuFind/src/VuFind/Content/Reviews/Guardian.php @@ -65,9 +65,7 @@ class Guardian extends \VuFind\Content\AbstractBase $url = $url . "&api-key=" . $key; } - if ($this->logger) { - $this->logger->debug('Guardian request: ' . $url); - } + $this->debug('Guardian request: ' . $url); // Find out if there are any reviews: $result = $this->getHttpClient($url)->send(); diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/AbstractBase.php b/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/AbstractBase.php index 63d381f8bed0ea56e18cbf2cbb607920dcf0b384..d22aadebbf30063741cb1460ad4a7c3ed4f282be 100644 --- a/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/AbstractBase.php +++ b/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/AbstractBase.php @@ -26,7 +26,6 @@ * @link http://vufind.org/wiki/vufind2:hierarchy_components Wiki */ namespace VuFind\Hierarchy\TreeDataSource; -use Zend\Log\LoggerInterface; /** * Hierarchy Tree Data Source (abstract base) @@ -41,12 +40,7 @@ use Zend\Log\LoggerInterface; */ abstract class AbstractBase implements \Zend\Log\LoggerAwareInterface { - /** - * Logger object for debug info (or false for no debugging). - * - * @var LoggerInterface|bool - */ - protected $logger = false; + use \VuFind\Log\LoggerAwareTrait; /** * Hierarchy driver @@ -55,32 +49,6 @@ abstract class AbstractBase implements \Zend\Log\LoggerAwareInterface */ protected $hierarchyDriver = null; - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Output a debug message, if appropriate - * - * @param string $msg Message to display - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Get the hierarchy driver * diff --git a/module/VuFind/src/VuFind/ILS/Driver/Aleph.php b/module/VuFind/src/VuFind/ILS/Driver/Aleph.php index b209bfe39c472227accf1d3377beee7b55fd8699..4820df24b3dcc252a8b71d7fcf9897c317a91d6d 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Aleph.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Aleph.php @@ -37,7 +37,6 @@ */ namespace VuFind\ILS\Driver; use VuFind\Exception\ILS as ILSException; -use Zend\Log\LoggerInterface; use VuFindHttp\HttpServiceInterface; use DateTime; use VuFind\Exception\Date as DateException; @@ -304,6 +303,7 @@ class AlephRestfulException extends ILSException class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, \VuFindHttp\HttpServiceAwareInterface { + use \VuFind\Log\LoggerAwareTrait; use \VuFindHttp\HttpServiceAwareTrait; /** @@ -327,13 +327,6 @@ class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, */ protected $cacheManager; - /** - * Logger object for debug info (or false for no debugging). - * - * @var LoggerInterface|bool - */ - protected $logger = false; - /** * Date converter object * @@ -354,18 +347,6 @@ class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, $this->cacheManager = $cacheManager; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Initialize the driver. * @@ -505,7 +486,7 @@ class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, $replyCode = (string) $result->{'reply-code'}; if ($replyCode != "0000") { $replyText = (string) $result->{'reply-text'}; - $this->logger->err( + $this->logError( "DLF request failed", array( 'url' => $url, 'reply-code' => $replyCode, 'reply-message' => $replyText @@ -584,20 +565,6 @@ class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, return $result; } - /** - * Show a debug message. - * - * @param string $msg Debug message. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Convert an ID string into an array of library and ID within the library. * diff --git a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php index c7ddc7cdabaa7ecf70a6a0b1ab31c440f6ee10a8..b74750f26081abcc28cb1f8129e89d24d28ad5e5 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php +++ b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php @@ -28,7 +28,7 @@ * @link http://vufind.org/wiki/vufind2:building_an_ils_driver Wiki */ namespace VuFind\ILS\Driver; -use DOMDocument, VuFind\Exception\ILS as ILSException, Zend\Log\LoggerInterface; +use DOMDocument, VuFind\Exception\ILS as ILSException; /** * ILS Driver for VuFind to query availability information via DAIA. @@ -43,6 +43,8 @@ use DOMDocument, VuFind\Exception\ILS as ILSException, Zend\Log\LoggerInterface; */ class DAIA extends AbstractBase implements \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Base URL * @@ -50,39 +52,6 @@ class DAIA extends AbstractBase implements \Zend\Log\LoggerAwareInterface */ protected $baseURL; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug(get_class($this) . ": $msg"); - } - } - /** * Initialize the driver. * diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index c58948ca52028d67c8c660701023d2da66f25ae4..b83645dc61971771b8ce86e1587730adf77c1834 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -30,8 +30,7 @@ namespace VuFind\ILS\Driver; use VuFind\Exception\ILS as ILSException, Zend\ServiceManager\ServiceLocatorAwareInterface, - Zend\ServiceManager\ServiceLocatorInterface, - Zend\Log\LoggerInterface; + Zend\ServiceManager\ServiceLocatorInterface; /** * Multiple Backend Driver. @@ -48,6 +47,9 @@ use VuFind\Exception\ILS as ILSException, class MultiBackend extends AbstractBase implements ServiceLocatorAwareInterface, \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait { + logError as error; + } use \Zend\ServiceManager\ServiceLocatorAwareTrait; /** @@ -107,13 +109,6 @@ class MultiBackend extends AbstractBase */ protected $ilsAuth; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - /** * Constructor * @@ -127,18 +122,6 @@ class MultiBackend extends AbstractBase $this->ilsAuth = $ilsAuth; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Set the driver configuration. * @@ -1197,34 +1180,6 @@ class MultiBackend extends AbstractBase return $driver && $this->methodSupported($driver, $method, $params); } - /** - * Log an error message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function error($msg) - { - if ($this->logger) { - $this->logger->err(get_class($this) . ": $msg"); - } - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug(get_class($this) . ": $msg"); - } - } - /** * Extract local ID from the given prefixed ID * diff --git a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php index c49cae17bc9a0b109e909c78bfb07023552a7e1b..39d8c60937f36e8377437884cd66657ace87cb85 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php @@ -30,7 +30,7 @@ namespace VuFind\ILS\Driver; use SoapClient, SoapFault, SoapHeader, VuFind\Exception\ILS as ILSException, Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorInterface; -use Zend\Log\LoggerInterface, Zend\Log\LoggerAwareInterface; +use Zend\Log\LoggerAwareInterface; /** * Symphony Web Services (symws) ILS Driver @@ -46,6 +46,7 @@ use Zend\Log\LoggerInterface, Zend\Log\LoggerAwareInterface; class Symphony extends AbstractBase implements ServiceLocatorAwareInterface, LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; use \Zend\ServiceManager\ServiceLocatorAwareTrait; /** @@ -62,39 +63,6 @@ class Symphony extends AbstractBase */ protected $policies; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug(get_class($this) . ": $msg"); - } - } - /** * Initialize the driver. * diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php index d58b5820bdf7b398b48ea154e97815eebb3ed1f4..3428c188c62b3c55b23b5d0dc25bcbc7dfa9b565 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php @@ -33,8 +33,7 @@ use File_MARC, PDO, PDOException, VuFind\Exception\Date as DateException, VuFind\Exception\ILS as ILSException, VuFind\I18n\Translator\TranslatorAwareInterface, - Zend\Validator\EmailAddress as EmailAddressValidator, - Zend\Log\LoggerInterface; + Zend\Validator\EmailAddress as EmailAddressValidator; /** * Voyager ILS Driver @@ -51,6 +50,9 @@ class Voyager extends AbstractBase implements TranslatorAwareInterface, \Zend\Log\LoggerAwareInterface { use \VuFind\I18n\Translator\TranslatorAwareTrait; + use \VuFind\Log\LoggerAwareTrait { + logError as error; + } /** * Database connection @@ -81,13 +83,6 @@ class Voyager extends AbstractBase */ protected $dateFormat; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - /** * Whether to use holdings sort groups to sort holdings records * @@ -105,32 +100,6 @@ class Voyager extends AbstractBase $this->dateFormat = $dateConverter; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug(get_class($this) . ": $msg"); - } - } - /** * Log an SQL statement debug message. * @@ -151,20 +120,6 @@ class Voyager extends AbstractBase } } - /** - * Log an error message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function error($msg) - { - if ($this->logger) { - $this->logger->err(get_class($this) . ": $msg"); - } - } - /** * Initialize the driver. * diff --git a/module/VuFind/src/VuFind/ImageLoader.php b/module/VuFind/src/VuFind/ImageLoader.php index 46cfeb39e5d341d2b1e39d313fce6be8b5b53fc0..0bcafdd42cc6437a2e65f0a0f284aba501dafe36 100644 --- a/module/VuFind/src/VuFind/ImageLoader.php +++ b/module/VuFind/src/VuFind/ImageLoader.php @@ -27,7 +27,6 @@ * @link http://vufind.org/wiki/use_of_external_content Wiki */ namespace VuFind; -use Zend\Log\LoggerInterface; /** * Base class for loading images (shared by Cover\Loader and QRCode\Loader) @@ -41,6 +40,8 @@ use Zend\Log\LoggerInterface; */ class ImageLoader implements \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Property for storing raw image data; may be null if image is unavailable * @@ -55,13 +56,6 @@ class ImageLoader implements \Zend\Log\LoggerAwareInterface */ protected $contentType = null; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - /** * Theme tools * @@ -108,32 +102,6 @@ class ImageLoader implements \Zend\Log\LoggerAwareInterface $this->themeTools = $theme; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Get the image data (not meant to be called until after image is populated) * diff --git a/module/VuFind/src/VuFind/Log/LoggerAwareTrait.php b/module/VuFind/src/VuFind/Log/LoggerAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..18521e2d2830f9a1c6497b3332efd91ec8fae901 --- /dev/null +++ b/module/VuFind/src/VuFind/Log/LoggerAwareTrait.php @@ -0,0 +1,105 @@ +<?php +/** + * Extension of \Zend\Log\LoggerAwareTrait with some convenience methods. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Error_Logging + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace VuFind\Log; + +/** + * Extension of \Zend\Log\LoggerAwareTrait with some convenience methods. + * + * @category VuFind2 + * @package Error_Logging + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +trait LoggerAwareTrait +{ + use \Zend\Log\LoggerAwareTrait; + + /** + * Log an error message. + * + * @param string $message Log message + * @param array $context Log context + * @param bool $prependClass Prepend class name to message? + * + * @return void + */ + protected function logError($msg, array $context = [], $prependClass = true) + { + return $this->log('err', $msg, $context, $prependClass); + } + + /** + * Log a warning message. + * + * @param string $message Log message + * @param array $context Log context + * @param bool $prependClass Prepend class name to message? + * + * @return void + */ + protected function logWarning($msg, array $context = [], $prependClass = true) + { + return $this->log('warn', $msg, $context, $prependClass); + } + + /** + * Log a debug message. + * + * @param string $message Log message + * @param array $context Log context + * @param bool $prependClass Prepend class name to message? + * + * @return void + */ + protected function debug($msg, array $context = [], $prependClass = true) + { + return $this->log('debug', $msg, $context, $prependClass); + } + + /** + * Send a message to the logger. + * + * @param string $level Log level + * @param string $message Log message + * @param array $context Log context + * @param bool $prependClass Prepend class name to message? + * + * @return void + */ + protected function log($level, $message, array $context = [], + $prependClass = false + ) { + if ($this->logger) { + if ($prependClass) { + $message = get_class($this) . ': ' . $message; + } + $this->logger->$level($message, $context); + } + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php b/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php index 471213aba60b3cd51557ec07fdb9bc5a08f30881..776b093bdccbf69be91f5e3f58b0cd8cc3a51272 100644 --- a/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php +++ b/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php @@ -27,7 +27,7 @@ * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki */ namespace VuFind\Recommend; -use Zend\Feed\Reader\Reader as FeedReader, Zend\Log\LoggerInterface; +use Zend\Feed\Reader\Reader as FeedReader; /** * EuropeanaResults Recommendations Module @@ -44,6 +44,7 @@ use Zend\Feed\Reader\Reader as FeedReader, Zend\Log\LoggerInterface; class EuropeanaResults implements RecommendInterface, \VuFindHttp\HttpServiceAwareInterface, \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; use \VuFindHttp\HttpServiceAwareTrait; /** @@ -116,13 +117,6 @@ class EuropeanaResults implements RecommendInterface, */ protected $results; - /** - * Logger (or false for none) - * - * @var LoggerInterface|bool - */ - protected $logger = false; - /** * Constructor * @@ -133,32 +127,6 @@ class EuropeanaResults implements RecommendInterface, $this->key = $key; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * setConfig * diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/AbstractBackend.php b/module/VuFindSearch/src/VuFindSearch/Backend/AbstractBackend.php index a7098824dcf783795b6e740b143f2546bf34982a..438badc801d1f044fddc1b7a6012c717962888db 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/AbstractBackend.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/AbstractBackend.php @@ -32,7 +32,7 @@ use VuFindSearch\Response\RecordCollectionFactoryInterface; use VuFindSearch\Backend\BackendInterface; -use Zend\Log\LoggerInterface, Zend\Log\LoggerAwareInterface; +use Zend\Log\LoggerAwareInterface; /** * Abstract backend. @@ -45,6 +45,8 @@ use Zend\Log\LoggerInterface, Zend\Log\LoggerAwareInterface; */ abstract class AbstractBackend implements BackendInterface, LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Record collection factory. * @@ -52,13 +54,6 @@ abstract class AbstractBackend implements BackendInterface, LoggerAwareInterface */ protected $collectionFactory = null; - /** - * Logger, if any. - * - * @var LoggerInterface - */ - protected $logger = null; - /** * Backend identifier. * @@ -78,18 +73,6 @@ abstract class AbstractBackend implements BackendInterface, LoggerAwareInterface $this->identifier = $identifier; } - /** - * Set the Logger. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Return backend identifier. * @@ -139,20 +122,4 @@ abstract class AbstractBackend implements BackendInterface, LoggerAwareInterface } return $response; } - - /** - * Send a message to the logger. - * - * @param string $level Log level - * @param string $message Log message - * @param array $context Log context - * - * @return void - */ - protected function log($level, $message, array $context = array()) - { - if ($this->logger) { - $this->logger->$level($message, $context); - } - } } \ No newline at end of file diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php index e4f93608377e2056a470a4a1796d3713a2d31caf..88a6f760e7119c04b6325e13b51a998142b5001b 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php @@ -30,7 +30,6 @@ namespace VuFindSearch\Backend\EDS; require_once dirname(__FILE__) . '/Base.php'; use Zend\Http\Client as Zend2HttpClient; use Zend\Log\LoggerAwareInterface; -use Zend\Log\LoggerInterface; use Zend\Http\Client\Adapter\Curl as CurlAdapter; /** @@ -44,31 +43,14 @@ use Zend\Http\Client\Adapter\Curl as CurlAdapter; */ class Zend2 extends EdsApi_REST_Base implements LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * The HTTP Request object to execute EDS API transactions * @var Zend2HttpClient */ protected $client; - /** - * Logger object for debug info (or false for no debugging). - * - * @var LoggerInterface|bool - */ - protected $logger = false; - - /** - * Set the logger to use - * - * @param LoggerInterface $logger Logger to set - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Print a message if debug is enabled. * diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EIT/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/EIT/Connector.php index 46c96e17ddbe1049b345906b8503fdc9efed65af..9fa9a6baf93454e9eb42facf9f0e6bf0c6d6b95d 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/EIT/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/EIT/Connector.php @@ -33,7 +33,6 @@ use VuFindSearch\Backend\Exception\HttpErrorException; use Zend\Http\Request; -use Zend\Log\LoggerInterface; /** * Central class for connecting to EIT resources used by VuFind. * @@ -43,8 +42,10 @@ use Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/system_classes Wiki */ -class Connector +class Connector implements \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Base url for searches * @@ -73,13 +74,6 @@ class Connector */ protected $pwd; - /** - * Logger instance. - * - * @var LoggerInterface - */ - protected $logger = false; - /** * Array of 3-character EBSCO database abbreviations to include in search * @@ -105,32 +99,6 @@ class Connector $this->dbs = $dbs; } - /** - * Set logger instance. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Execute a search. * diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php index 74a15a60decaf155b53eabb08421306ce87e134e..dd1c5d9908a8f85a843f1e392c3ccc7b5e526971 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php @@ -29,7 +29,6 @@ */ namespace VuFindSearch\Backend\LibGuides; use Zend\Http\Client as HttpClient; -use Zend\Log\LoggerInterface; /** * LibGuides connector. @@ -41,14 +40,9 @@ use Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org */ -class Connector +class Connector implements \Zend\Log\LoggerAwareInterface { - /** - * Logger instance. - * - * @var LoggerInterface - */ - protected $logger; + use \VuFind\Log\LoggerAwareTrait; /** * The HTTP_Request object used for API transactions @@ -99,18 +93,6 @@ class Connector $this->client = $client; } - /** - * Set logger instance. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Execute a search. adds all the querystring parameters into * $this->client and returns the parsed response @@ -135,9 +117,7 @@ class Connector = array_slice($result['documents'], $offset, $limit); } catch (\Exception $e) { if ($returnErr) { - if ($this->logger) { - $this->logger->debug($e->getMessage()); - } + $this->debug($e->getMessage()); $result = array( 'recordCount' => 0, 'documents' => array(), @@ -163,9 +143,7 @@ class Connector */ protected function call($qs, $method = 'GET') { - if ($this->logger) { - $this->logger->debug("{$method}: {$this->host}{$qs}"); - } + $this->debug("{$method}: {$this->host}{$qs}"); $this->client->resetParameters(); if ($method == 'GET') { $baseUrl = $this->host . $qs; diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Pazpar2/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Pazpar2/Connector.php index 5e13191657dae1efe3d583211ef5ffe2b55fde6b..515d88e168289b49b1eb0a68f9771d698ab8b4b4 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Pazpar2/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Pazpar2/Connector.php @@ -32,8 +32,6 @@ use VuFindSearch\Backend\Exception\HttpErrorException; use Zend\Http\Request; -use Zend\Log\LoggerInterface; - /** * Central class for connecting to resources used by VuFind. * @@ -43,8 +41,10 @@ use Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/system_classes Wiki */ -class Connector +class Connector implements \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Base url for searches * @@ -66,13 +66,6 @@ class Connector */ protected $session = false; - /** - * Logger instance. - * - * @var LoggerInterface - */ - protected $logger = false; - /** * Constructor * @@ -96,18 +89,6 @@ class Connector } } - /** - * Set logger instance. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Initializes a session. Returns session ID to be used in subsequent requests. * Adds session to the base @@ -175,24 +156,20 @@ class Connector */ protected function send(\Zend\Http\Client $client) { - if ($this->logger) { - $this->logger->debug( - sprintf('=> %s %s', $client->getMethod(), $client->getUri()) - ); - } + $this->debug( + sprintf('=> %s %s', $client->getMethod(), $client->getUri()) + ); $time = microtime(true); $response = $client->send(); $time = microtime(true) - $time; - if ($this->logger) { - $this->logger->debug( - sprintf( - '<= %s %s', $response->getStatusCode(), - $response->getReasonPhrase() - ), array('time' => $time) - ); - } + $this->debug( + sprintf( + '<= %s %s', $response->getStatusCode(), + $response->getReasonPhrase() + ), array('time' => $time) + ); if (!$response->isSuccess()) { throw HttpErrorException::createFromResponse($response); diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php index 686d500e9b063d0389d9a527ed1d13ab2247a31f..f10824b56953b0d8dca2ba638d58322221e3aa09 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php @@ -31,7 +31,6 @@ */ namespace VuFindSearch\Backend\Primo; use Zend\Http\Client as HttpClient; -use Zend\Log\LoggerInterface; /** * Primo Central connector. @@ -45,14 +44,9 @@ use Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org */ -class Connector +class Connector implements \Zend\Log\LoggerAwareInterface { - /** - * Logger instance. - * - * @var LoggerInterface - */ - protected $logger; + use \VuFind\Log\LoggerAwareTrait; /** * The HTTP_Request object used for API transactions @@ -100,18 +94,6 @@ class Connector $this->client = $client; } - /** - * Set logger instance. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Execute a search. adds all the querystring parameters into * $this->client and returns the parsed response @@ -165,9 +147,7 @@ class Connector $result = $this->performSearch($institution, $terms, $args); } catch (\Exception $e) { if ($args["returnErr"]) { - if ($this->logger) { - $this->logger->debug($e->getMessage()); - } + $this->debug($e->getMessage()); return array( 'recordCount' => 0, 'documents' => array(), @@ -354,9 +334,7 @@ class Connector */ protected function call($qs, $method = 'GET') { - if ($this->logger) { - $this->logger->debug("{$method}: {$this->host}{$qs}"); - } + $this->debug("{$method}: {$this->host}{$qs}"); $this->client->resetParameters(); if ($method == 'GET') { $baseUrl = $this->host . $qs; diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/SRU/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/SRU/Connector.php index 6bc126e4b61d6cd6d3d54383d91441890603bc91..e6789ed88d34818392caffeb197064891b393432 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/SRU/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/SRU/Connector.php @@ -32,9 +32,6 @@ use VuFindSearch\Backend\Exception\BackendException; use VuFind\XSLT\Processor as XSLTProcessor; -use Zend\Log\LoggerAwareInterface; -use Zend\Log\LoggerInterface; - /** * SRU Search Interface * @@ -44,14 +41,9 @@ use Zend\Log\LoggerInterface; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ -class Connector implements LoggerAwareInterface +class Connector implements \Zend\Log\LoggerAwareInterface { - /** - * Logger object for debug info (or false for no debugging). - * - * @var LoggerInterface|bool - */ - protected $logger = false; + use \VuFind\Log\LoggerAwareTrait; /** * Whether to Serialize to a PHP Array or not. @@ -96,32 +88,6 @@ class Connector implements LoggerAwareInterface $this->client = $client; } - /** - * Set the logger - * - * @param LoggerInterface $logger Logger to use. - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * Log a debug message. - * - * @param string $msg Message to log. - * - * @return void - */ - protected function debug($msg) - { - if ($this->logger) { - $this->logger->debug($msg); - } - } - /** * Get records similar to one record * diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php index 1e1f0244318b8a105e7aa2f76f6d487c50db536d..1029c535aa5cf6177cf2132a9c75855a33c63c1a 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php @@ -45,8 +45,6 @@ use Zend\Http\Request; use Zend\Http\Client as HttpClient; use Zend\Http\Client\Adapter\AdapterInterface; -use Zend\Log\LoggerInterface; - use InvalidArgumentException; use XMLWriter; @@ -61,8 +59,10 @@ use XMLWriter; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org */ -class Connector +class Connector implements \Zend\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; + /** * Maximum length of a GET url. * @@ -74,13 +74,6 @@ class Connector */ const MAX_GET_URL_LENGTH = 2048; - /** - * Logger instance. - * - * @var LoggerInterface - */ - protected $logger; - /** * URL of SOLR core. * @@ -284,18 +277,6 @@ class Connector return $this->send($client); } - /** - * Set logger instance. - * - * @param LoggerInterface $logger Logger - * - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * Set the HTTP proxy service. * @@ -386,9 +367,7 @@ class Connector $client = $this->createClient($url, $method); } - if ($this->logger) { - $this->logger->debug(sprintf('Query %s', $paramString)); - } + $this->debug(sprintf('Query %s', $paramString)); return $this->send($client); } @@ -404,24 +383,20 @@ class Connector */ protected function send(HttpClient $client) { - if ($this->logger) { - $this->logger->debug( - sprintf('=> %s %s', $client->getMethod(), $client->getUri()) - ); - } + $this->debug( + sprintf('=> %s %s', $client->getMethod(), $client->getUri()) + ); $time = microtime(true); $response = $client->send(); $time = microtime(true) - $time; - if ($this->logger) { - $this->logger->debug( - sprintf( - '<= %s %s', $response->getStatusCode(), - $response->getReasonPhrase() - ), array('time' => $time) - ); - } + $this->debug( + sprintf( + '<= %s %s', $response->getStatusCode(), + $response->getReasonPhrase() + ), array('time' => $time) + ); if (!$response->isSuccess()) { throw HttpErrorException::createFromResponse($response);