From 000baab3b887f36ddfdff2a61a6c2dbf37aa9563 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 1 Sep 2016 15:34:18 -0400 Subject: [PATCH] Treat different HTTP status exceptions as different logging severities. --- module/VuFind/src/VuFind/Log/Logger.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/Log/Logger.php b/module/VuFind/src/VuFind/Log/Logger.php index 04b7faa199a..289e9381d4f 100644 --- a/module/VuFind/src/VuFind/Log/Logger.php +++ b/module/VuFind/src/VuFind/Log/Logger.php @@ -290,6 +290,24 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface return parent::log($priority, $message, $extra); } + /** + * Given an exception, return a severity level for logging purposes. + * + * @param \Exception $error Exception to analyze + * + * @return int + */ + protected function getSeverityFromException($error) + { + // Treat unexpected or 5xx errors as more severe than 4xx errors. + if ($error instanceof \VuFind\Exception\HttpStatusInterface + && in_array($error->getHttpStatus(), [403, 404]) + ) { + return BaseLogger::WARN; + } + return BaseLogger::CRIT; + } + /** * Log an exception triggered by ZF2 for administrative purposes. * @@ -350,7 +368,7 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface 5 => $baseError . $detailedServer . $detailedBacktrace ]; - $this->log(BaseLogger::CRIT, $errorDetails); + $this->log($this->getSeverityFromException($error), $errorDetails); } /** -- GitLab