1 | <?php |
||
33 | class CerbereLoggerListener implements EventSubscriberInterface, LoggerAwareInterface |
||
34 | { |
||
35 | /** |
||
36 | * @var LoggerInterface |
||
37 | */ |
||
38 | protected $logger; |
||
39 | |||
40 | /** |
||
41 | * Mapping of event to log level. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $logLevelMappings = array( |
||
46 | CerbereEvents::CERBERE_FILE_DISCOVERED => LogLevel::INFO, |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * @param LoggerInterface $logger |
||
51 | */ |
||
52 | public function __construct(LoggerInterface $logger) |
||
56 | |||
57 | /** |
||
58 | * Returns the log level mapping for an event. |
||
59 | * |
||
60 | * @param string $eventName |
||
61 | * |
||
62 | * @return string |
||
63 | * |
||
64 | * @throws \DomainException |
||
65 | */ |
||
66 | public function getLogLevelMapping($eventName) |
||
74 | |||
75 | /** |
||
76 | * @return LoggerInterface |
||
77 | */ |
||
78 | public function getLogger() |
||
82 | |||
83 | /** |
||
84 | * Sets a logger instance on the object |
||
85 | * |
||
86 | * @param LoggerInterface $logger |
||
87 | * |
||
88 | * @return null |
||
89 | */ |
||
90 | public function setLogger(LoggerInterface $logger) |
||
94 | |||
95 | /** |
||
96 | * Returns an array of event names this subscriber wants to listen to. |
||
97 | * |
||
98 | * The array keys are event names and the value can be: |
||
99 | * |
||
100 | * * The method name to call (priority defaults to 0) |
||
101 | * * An array composed of the method name to call and the priority |
||
102 | * * An array of arrays composed of the method names to call and respective |
||
103 | * priorities, or 0 if unset |
||
104 | * |
||
105 | * For instance: |
||
106 | * |
||
107 | * * array('eventName' => 'methodName') |
||
108 | * * array('eventName' => array('methodName', $priority)) |
||
109 | * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) |
||
110 | * |
||
111 | * @return array The event names to listen to |
||
112 | */ |
||
113 | public static function getSubscribedEvents() |
||
119 | |||
120 | /** |
||
121 | * @param CerbereFileDiscoverEvent $event |
||
122 | */ |
||
123 | public function onFileDiscover(CerbereFileDiscoverEvent $event) |
||
132 | |||
133 | /** |
||
134 | * @param string $method |
||
135 | * @param string $message |
||
136 | * @param array $context |
||
137 | */ |
||
138 | protected function log($method, $message, array $context = array()) |
||
142 | |||
143 | /** |
||
144 | * Sets the log level mapping for an event. |
||
145 | * |
||
146 | * @param string $eventName |
||
147 | * @param string|false $logLevel |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function setLogLevelMapping($eventName, $logLevel) |
||
157 | } |
||
158 |