Skip to content

Commit

Permalink
Fix enotice when Log service is swapped out
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Apr 26, 2021
1 parent 6ae34f2 commit 1c420d6
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Civi/API/LogObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
];
}

}

0 comments on commit 1c420d6

Please sign in to comment.