From 1c420d649cce3cbe3e83c91ab853a935c12987a3 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 26 Apr 2021 17:23:13 +1200 Subject: [PATCH] Fix enotice when Log service is swapped out This function is calling a property on the psr_log service that may not exist. If the service is swapped out there is no reason the replacement should have this property. Given it's just an array I think duplicating it is the most readable --- Civi/API/LogObserver.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Civi/API/LogObserver.php b/Civi/API/LogObserver.php index b92eaa67d404..dcb6491a3230 100644 --- a/Civi/API/LogObserver.php +++ b/Civi/API/LogObserver.php @@ -23,7 +23,7 @@ class LogObserver extends \Log_observer { * @param array $event */ public function notify($event) { - $levels = \Civi::log()->map; + $levels = $this->getLevels(); $event['level'] = array_search($event['priority'], $levels); // Extract [civi.tag] from message string // As noted in \CRM_Core_Error_Log::log() the $context array gets prematurely converted to string with print_r() so we have to un-flatten it here @@ -41,4 +41,28 @@ public function getMessages() { return self::$messages; } + /** + * Get the debugging levels. + * + * These are also on the CRM_Error_Log class but are not + * part of the interface that class implements so + * calling it from outside that class is unsafe. + * + * Yes, it's duplicated - but it's just an array! + * + * @return array + */ + public function getLevels(): array { + return [ + \Psr\Log\LogLevel::DEBUG => PEAR_LOG_DEBUG, + \Psr\Log\LogLevel::INFO => PEAR_LOG_INFO, + \Psr\Log\LogLevel::NOTICE => PEAR_LOG_NOTICE, + \Psr\Log\LogLevel::WARNING => PEAR_LOG_WARNING, + \Psr\Log\LogLevel::ERROR => PEAR_LOG_ERR, + \Psr\Log\LogLevel::CRITICAL => PEAR_LOG_CRIT, + \Psr\Log\LogLevel::ALERT => PEAR_LOG_ALERT, + \Psr\Log\LogLevel::EMERGENCY => PEAR_LOG_EMERG, + ]; + } + }