@@ -35,229 +35,229 @@ |
||
35 | 35 | |
36 | 36 | final class PsrLoggerAdapter implements LoggerInterface { |
37 | 37 | |
38 | - /** @var ILogger */ |
|
39 | - private $logger; |
|
38 | + /** @var ILogger */ |
|
39 | + private $logger; |
|
40 | 40 | |
41 | - public function __construct(ILogger $logger) { |
|
42 | - $this->logger = $logger; |
|
43 | - } |
|
41 | + public function __construct(ILogger $logger) { |
|
42 | + $this->logger = $logger; |
|
43 | + } |
|
44 | 44 | |
45 | - private function containsThrowable(array $context): bool { |
|
46 | - return array_key_exists('exception', $context) && $context['exception'] instanceof Throwable; |
|
47 | - } |
|
45 | + private function containsThrowable(array $context): bool { |
|
46 | + return array_key_exists('exception', $context) && $context['exception'] instanceof Throwable; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * System is unusable. |
|
51 | - * |
|
52 | - * @param string $message |
|
53 | - * @param array $context |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function emergency($message, array $context = []): void { |
|
58 | - if ($this->containsThrowable($context)) { |
|
59 | - $this->logger->logException($context['exception'], array_merge( |
|
60 | - [ |
|
61 | - 'message' => $message, |
|
62 | - 'level' => ILogger::FATAL, |
|
63 | - ], |
|
64 | - $context |
|
65 | - )); |
|
66 | - } else { |
|
67 | - $this->logger->emergency($message, $context); |
|
68 | - } |
|
69 | - } |
|
49 | + /** |
|
50 | + * System is unusable. |
|
51 | + * |
|
52 | + * @param string $message |
|
53 | + * @param array $context |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function emergency($message, array $context = []): void { |
|
58 | + if ($this->containsThrowable($context)) { |
|
59 | + $this->logger->logException($context['exception'], array_merge( |
|
60 | + [ |
|
61 | + 'message' => $message, |
|
62 | + 'level' => ILogger::FATAL, |
|
63 | + ], |
|
64 | + $context |
|
65 | + )); |
|
66 | + } else { |
|
67 | + $this->logger->emergency($message, $context); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Action must be taken immediately. |
|
73 | - * |
|
74 | - * Example: Entire website down, database unavailable, etc. This should |
|
75 | - * trigger the SMS alerts and wake you up. |
|
76 | - * |
|
77 | - * @param string $message |
|
78 | - * @param array $context |
|
79 | - * |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function alert($message, array $context = []) { |
|
83 | - if ($this->containsThrowable($context)) { |
|
84 | - $this->logger->logException($context['exception'], array_merge( |
|
85 | - [ |
|
86 | - 'message' => $message, |
|
87 | - 'level' => ILogger::ERROR, |
|
88 | - ], |
|
89 | - $context |
|
90 | - )); |
|
91 | - } else { |
|
92 | - $this->logger->alert($message, $context); |
|
93 | - } |
|
94 | - } |
|
71 | + /** |
|
72 | + * Action must be taken immediately. |
|
73 | + * |
|
74 | + * Example: Entire website down, database unavailable, etc. This should |
|
75 | + * trigger the SMS alerts and wake you up. |
|
76 | + * |
|
77 | + * @param string $message |
|
78 | + * @param array $context |
|
79 | + * |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function alert($message, array $context = []) { |
|
83 | + if ($this->containsThrowable($context)) { |
|
84 | + $this->logger->logException($context['exception'], array_merge( |
|
85 | + [ |
|
86 | + 'message' => $message, |
|
87 | + 'level' => ILogger::ERROR, |
|
88 | + ], |
|
89 | + $context |
|
90 | + )); |
|
91 | + } else { |
|
92 | + $this->logger->alert($message, $context); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Critical conditions. |
|
98 | - * |
|
99 | - * Example: Application component unavailable, unexpected exception. |
|
100 | - * |
|
101 | - * @param string $message |
|
102 | - * @param array $context |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function critical($message, array $context = []) { |
|
107 | - if ($this->containsThrowable($context)) { |
|
108 | - $this->logger->logException($context['exception'], array_merge( |
|
109 | - [ |
|
110 | - 'message' => $message, |
|
111 | - 'level' => ILogger::ERROR, |
|
112 | - ], |
|
113 | - $context |
|
114 | - )); |
|
115 | - } else { |
|
116 | - $this->logger->critical($message, $context); |
|
117 | - } |
|
118 | - } |
|
96 | + /** |
|
97 | + * Critical conditions. |
|
98 | + * |
|
99 | + * Example: Application component unavailable, unexpected exception. |
|
100 | + * |
|
101 | + * @param string $message |
|
102 | + * @param array $context |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function critical($message, array $context = []) { |
|
107 | + if ($this->containsThrowable($context)) { |
|
108 | + $this->logger->logException($context['exception'], array_merge( |
|
109 | + [ |
|
110 | + 'message' => $message, |
|
111 | + 'level' => ILogger::ERROR, |
|
112 | + ], |
|
113 | + $context |
|
114 | + )); |
|
115 | + } else { |
|
116 | + $this->logger->critical($message, $context); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Runtime errors that do not require immediate action but should typically |
|
122 | - * be logged and monitored. |
|
123 | - * |
|
124 | - * @param string $message |
|
125 | - * @param array $context |
|
126 | - * |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function error($message, array $context = []) { |
|
130 | - if ($this->containsThrowable($context)) { |
|
131 | - $this->logger->logException($context['exception'], array_merge( |
|
132 | - [ |
|
133 | - 'message' => $message, |
|
134 | - 'level' => ILogger::ERROR, |
|
135 | - ], |
|
136 | - $context |
|
137 | - )); |
|
138 | - } else { |
|
139 | - $this->logger->error($message, $context); |
|
140 | - } |
|
141 | - } |
|
120 | + /** |
|
121 | + * Runtime errors that do not require immediate action but should typically |
|
122 | + * be logged and monitored. |
|
123 | + * |
|
124 | + * @param string $message |
|
125 | + * @param array $context |
|
126 | + * |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function error($message, array $context = []) { |
|
130 | + if ($this->containsThrowable($context)) { |
|
131 | + $this->logger->logException($context['exception'], array_merge( |
|
132 | + [ |
|
133 | + 'message' => $message, |
|
134 | + 'level' => ILogger::ERROR, |
|
135 | + ], |
|
136 | + $context |
|
137 | + )); |
|
138 | + } else { |
|
139 | + $this->logger->error($message, $context); |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Exceptional occurrences that are not errors. |
|
145 | - * |
|
146 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
147 | - * that are not necessarily wrong. |
|
148 | - * |
|
149 | - * @param string $message |
|
150 | - * @param array $context |
|
151 | - * |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public function warning($message, array $context = []) { |
|
155 | - if ($this->containsThrowable($context)) { |
|
156 | - $this->logger->logException($context['exception'], array_merge( |
|
157 | - [ |
|
158 | - 'message' => $message, |
|
159 | - 'level' => ILogger::WARN, |
|
160 | - ], |
|
161 | - $context |
|
162 | - )); |
|
163 | - } else { |
|
164 | - $this->logger->warning($message, $context); |
|
165 | - } |
|
166 | - } |
|
143 | + /** |
|
144 | + * Exceptional occurrences that are not errors. |
|
145 | + * |
|
146 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
147 | + * that are not necessarily wrong. |
|
148 | + * |
|
149 | + * @param string $message |
|
150 | + * @param array $context |
|
151 | + * |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public function warning($message, array $context = []) { |
|
155 | + if ($this->containsThrowable($context)) { |
|
156 | + $this->logger->logException($context['exception'], array_merge( |
|
157 | + [ |
|
158 | + 'message' => $message, |
|
159 | + 'level' => ILogger::WARN, |
|
160 | + ], |
|
161 | + $context |
|
162 | + )); |
|
163 | + } else { |
|
164 | + $this->logger->warning($message, $context); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Normal but significant events. |
|
170 | - * |
|
171 | - * @param string $message |
|
172 | - * @param array $context |
|
173 | - * |
|
174 | - * @return void |
|
175 | - */ |
|
176 | - public function notice($message, array $context = []) { |
|
177 | - if ($this->containsThrowable($context)) { |
|
178 | - $this->logger->logException($context['exception'], array_merge( |
|
179 | - [ |
|
180 | - 'message' => $message, |
|
181 | - 'level' => ILogger::INFO, |
|
182 | - ], |
|
183 | - $context |
|
184 | - )); |
|
185 | - } else { |
|
186 | - $this->logger->notice($message, $context); |
|
187 | - } |
|
188 | - } |
|
168 | + /** |
|
169 | + * Normal but significant events. |
|
170 | + * |
|
171 | + * @param string $message |
|
172 | + * @param array $context |
|
173 | + * |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + public function notice($message, array $context = []) { |
|
177 | + if ($this->containsThrowable($context)) { |
|
178 | + $this->logger->logException($context['exception'], array_merge( |
|
179 | + [ |
|
180 | + 'message' => $message, |
|
181 | + 'level' => ILogger::INFO, |
|
182 | + ], |
|
183 | + $context |
|
184 | + )); |
|
185 | + } else { |
|
186 | + $this->logger->notice($message, $context); |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Interesting events. |
|
192 | - * |
|
193 | - * Example: User logs in, SQL logs. |
|
194 | - * |
|
195 | - * @param string $message |
|
196 | - * @param array $context |
|
197 | - * |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public function info($message, array $context = []) { |
|
201 | - if ($this->containsThrowable($context)) { |
|
202 | - $this->logger->logException($context['exception'], array_merge( |
|
203 | - [ |
|
204 | - 'message' => $message, |
|
205 | - 'level' => ILogger::INFO, |
|
206 | - ], |
|
207 | - $context |
|
208 | - )); |
|
209 | - } else { |
|
210 | - $this->logger->info($message, $context); |
|
211 | - } |
|
212 | - } |
|
190 | + /** |
|
191 | + * Interesting events. |
|
192 | + * |
|
193 | + * Example: User logs in, SQL logs. |
|
194 | + * |
|
195 | + * @param string $message |
|
196 | + * @param array $context |
|
197 | + * |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public function info($message, array $context = []) { |
|
201 | + if ($this->containsThrowable($context)) { |
|
202 | + $this->logger->logException($context['exception'], array_merge( |
|
203 | + [ |
|
204 | + 'message' => $message, |
|
205 | + 'level' => ILogger::INFO, |
|
206 | + ], |
|
207 | + $context |
|
208 | + )); |
|
209 | + } else { |
|
210 | + $this->logger->info($message, $context); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Detailed debug information. |
|
216 | - * |
|
217 | - * @param string $message |
|
218 | - * @param array $context |
|
219 | - * |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - public function debug($message, array $context = []) { |
|
223 | - if ($this->containsThrowable($context)) { |
|
224 | - $this->logger->logException($context['exception'], array_merge( |
|
225 | - [ |
|
226 | - 'message' => $message, |
|
227 | - 'level' => ILogger::DEBUG, |
|
228 | - ], |
|
229 | - $context |
|
230 | - )); |
|
231 | - } else { |
|
232 | - $this->logger->debug($message, $context); |
|
233 | - } |
|
234 | - } |
|
214 | + /** |
|
215 | + * Detailed debug information. |
|
216 | + * |
|
217 | + * @param string $message |
|
218 | + * @param array $context |
|
219 | + * |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + public function debug($message, array $context = []) { |
|
223 | + if ($this->containsThrowable($context)) { |
|
224 | + $this->logger->logException($context['exception'], array_merge( |
|
225 | + [ |
|
226 | + 'message' => $message, |
|
227 | + 'level' => ILogger::DEBUG, |
|
228 | + ], |
|
229 | + $context |
|
230 | + )); |
|
231 | + } else { |
|
232 | + $this->logger->debug($message, $context); |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Logs with an arbitrary level. |
|
238 | - * |
|
239 | - * @param mixed $level |
|
240 | - * @param string $message |
|
241 | - * @param array $context |
|
242 | - * |
|
243 | - * @return void |
|
244 | - * |
|
245 | - * @throws InvalidArgumentException |
|
246 | - */ |
|
247 | - public function log($level, $message, array $context = []) { |
|
248 | - if (!is_int($level) || $level < ILogger::DEBUG || $level > ILogger::FATAL) { |
|
249 | - throw new InvalidArgumentException('Nextcloud allows only integer log levels'); |
|
250 | - } |
|
251 | - if ($this->containsThrowable($context)) { |
|
252 | - $this->logger->logException($context['exception'], array_merge( |
|
253 | - [ |
|
254 | - 'message' => $message, |
|
255 | - 'level' => $level, |
|
256 | - ], |
|
257 | - $context |
|
258 | - )); |
|
259 | - } else { |
|
260 | - $this->logger->log($level, $message, $context); |
|
261 | - } |
|
262 | - } |
|
236 | + /** |
|
237 | + * Logs with an arbitrary level. |
|
238 | + * |
|
239 | + * @param mixed $level |
|
240 | + * @param string $message |
|
241 | + * @param array $context |
|
242 | + * |
|
243 | + * @return void |
|
244 | + * |
|
245 | + * @throws InvalidArgumentException |
|
246 | + */ |
|
247 | + public function log($level, $message, array $context = []) { |
|
248 | + if (!is_int($level) || $level < ILogger::DEBUG || $level > ILogger::FATAL) { |
|
249 | + throw new InvalidArgumentException('Nextcloud allows only integer log levels'); |
|
250 | + } |
|
251 | + if ($this->containsThrowable($context)) { |
|
252 | + $this->logger->logException($context['exception'], array_merge( |
|
253 | + [ |
|
254 | + 'message' => $message, |
|
255 | + 'level' => $level, |
|
256 | + ], |
|
257 | + $context |
|
258 | + )); |
|
259 | + } else { |
|
260 | + $this->logger->log($level, $message, $context); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | } |