Commit | Line | Data |
---|---|---|
2aafb0fc CW |
1 | <?php |
2 | ||
3 | ||
4 | namespace Civi\API; | |
5 | ||
6 | /** | |
7 | * API Error Log Observer | |
8 | * | |
9 | * @see \CRM_Core_Error_Log | |
10 | * @see \Civi\API\Subscriber\DebugSubscriber | |
11 | * | |
12 | * @package Civi\API | |
13 | */ | |
14 | class LogObserver extends \Log_observer { | |
15 | ||
16 | /** | |
17 | * @var array | |
18 | */ | |
19 | private static $messages = []; | |
20 | ||
21 | /** | |
22 | * @see \Log::_announce | |
23 | * @param array $event | |
24 | */ | |
25 | public function notify($event) { | |
82073f7b | 26 | $levels = \CRM_Core_Error_Log::getMap(); |
2aafb0fc CW |
27 | $event['level'] = array_search($event['priority'], $levels); |
28 | // Extract [civi.tag] from message string | |
29 | // 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 | |
30 | if (preg_match('/^(.*)\s*Array\s*\(\s*\[civi\.(\w+)] => (\w+)\s*\)/', $event['message'], $message)) { | |
31 | $event['message'] = $message[1]; | |
32 | $event[$message[2]] = $message[3]; | |
33 | } | |
34 | self::$messages[] = $event; | |
35 | } | |
36 | ||
37 | /** | |
38 | * @return array | |
39 | */ | |
40 | public function getMessages() { | |
41 | return self::$messages; | |
42 | } | |
43 | ||
44 | } |