Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
53 public function reset() | 53 public function reset() |
54 { | 54 { |
55 if ($this->logger && method_exists($this->logger, 'clear')) { | 55 if ($this->logger && method_exists($this->logger, 'clear')) { |
56 $this->logger->clear(); | 56 $this->logger->clear(); |
57 } | 57 } |
58 $this->data = array(); | 58 $this->data = []; |
59 } | 59 } |
60 | 60 |
61 /** | 61 /** |
62 * {@inheritdoc} | 62 * {@inheritdoc} |
63 */ | 63 */ |
77 * | 77 * |
78 * @return array An array of logs | 78 * @return array An array of logs |
79 */ | 79 */ |
80 public function getLogs() | 80 public function getLogs() |
81 { | 81 { |
82 return isset($this->data['logs']) ? $this->data['logs'] : array(); | 82 return isset($this->data['logs']) ? $this->data['logs'] : []; |
83 } | 83 } |
84 | 84 |
85 public function getPriorities() | 85 public function getPriorities() |
86 { | 86 { |
87 return isset($this->data['priorities']) ? $this->data['priorities'] : array(); | 87 return isset($this->data['priorities']) ? $this->data['priorities'] : []; |
88 } | 88 } |
89 | 89 |
90 public function countErrors() | 90 public function countErrors() |
91 { | 91 { |
92 return isset($this->data['error_count']) ? $this->data['error_count'] : 0; | 92 return isset($this->data['error_count']) ? $this->data['error_count'] : 0; |
107 return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0; | 107 return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0; |
108 } | 108 } |
109 | 109 |
110 public function getCompilerLogs() | 110 public function getCompilerLogs() |
111 { | 111 { |
112 return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : array(); | 112 return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : []; |
113 } | 113 } |
114 | 114 |
115 /** | 115 /** |
116 * {@inheritdoc} | 116 * {@inheritdoc} |
117 */ | 117 */ |
121 } | 121 } |
122 | 122 |
123 private function getContainerDeprecationLogs() | 123 private function getContainerDeprecationLogs() |
124 { | 124 { |
125 if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) { | 125 if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) { |
126 return array(); | 126 return []; |
127 } | 127 } |
128 | 128 |
129 $bootTime = filemtime($file); | 129 $bootTime = filemtime($file); |
130 $logs = array(); | 130 $logs = []; |
131 foreach (unserialize(file_get_contents($file)) as $log) { | 131 foreach (unserialize(file_get_contents($file)) as $log) { |
132 $log['context'] = array('exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])); | 132 $log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])]; |
133 $log['timestamp'] = $bootTime; | 133 $log['timestamp'] = $bootTime; |
134 $log['priority'] = 100; | 134 $log['priority'] = 100; |
135 $log['priorityName'] = 'DEBUG'; | 135 $log['priorityName'] = 'DEBUG'; |
136 $log['channel'] = '-'; | 136 $log['channel'] = '-'; |
137 $log['scream'] = false; | 137 $log['scream'] = false; |
143 } | 143 } |
144 | 144 |
145 private function getContainerCompilerLogs() | 145 private function getContainerCompilerLogs() |
146 { | 146 { |
147 if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) { | 147 if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) { |
148 return array(); | 148 return []; |
149 } | 149 } |
150 | 150 |
151 $logs = array(); | 151 $logs = []; |
152 foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) { | 152 foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) { |
153 $log = explode(': ', $log, 2); | 153 $log = explode(': ', $log, 2); |
154 if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) { | 154 if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) { |
155 $log = array('Unknown Compiler Pass', implode(': ', $log)); | 155 $log = ['Unknown Compiler Pass', implode(': ', $log)]; |
156 } | 156 } |
157 | 157 |
158 $logs[$log[0]][] = array('message' => $log[1]); | 158 $logs[$log[0]][] = ['message' => $log[1]]; |
159 } | 159 } |
160 | 160 |
161 return $logs; | 161 return $logs; |
162 } | 162 } |
163 | 163 |
164 private function sanitizeLogs($logs) | 164 private function sanitizeLogs($logs) |
165 { | 165 { |
166 $sanitizedLogs = array(); | 166 $sanitizedLogs = []; |
167 $silencedLogs = array(); | 167 $silencedLogs = []; |
168 | 168 |
169 foreach ($logs as $log) { | 169 foreach ($logs as $log) { |
170 if (!$this->isSilencedOrDeprecationErrorLog($log)) { | 170 if (!$this->isSilencedOrDeprecationErrorLog($log)) { |
171 $sanitizedLogs[] = $log; | 171 $sanitizedLogs[] = $log; |
172 | 172 |
181 continue; | 181 continue; |
182 } | 182 } |
183 $silencedLogs[$h] = true; | 183 $silencedLogs[$h] = true; |
184 | 184 |
185 if (!isset($sanitizedLogs[$message])) { | 185 if (!isset($sanitizedLogs[$message])) { |
186 $sanitizedLogs[$message] = $log + array( | 186 $sanitizedLogs[$message] = $log + [ |
187 'errorCount' => 0, | 187 'errorCount' => 0, |
188 'scream' => true, | 188 'scream' => true, |
189 ); | 189 ]; |
190 } | 190 } |
191 $sanitizedLogs[$message]['errorCount'] += $exception->count; | 191 $sanitizedLogs[$message]['errorCount'] += $exception->count; |
192 | 192 |
193 continue; | 193 continue; |
194 } | 194 } |
196 $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}\0{$message}", true); | 196 $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}\0{$message}", true); |
197 | 197 |
198 if (isset($sanitizedLogs[$errorId])) { | 198 if (isset($sanitizedLogs[$errorId])) { |
199 ++$sanitizedLogs[$errorId]['errorCount']; | 199 ++$sanitizedLogs[$errorId]['errorCount']; |
200 } else { | 200 } else { |
201 $log += array( | 201 $log += [ |
202 'errorCount' => 1, | 202 'errorCount' => 1, |
203 'scream' => false, | 203 'scream' => false, |
204 ); | 204 ]; |
205 | 205 |
206 $sanitizedLogs[$errorId] = $log; | 206 $sanitizedLogs[$errorId] = $log; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
220 | 220 |
221 if ($exception instanceof SilencedErrorContext) { | 221 if ($exception instanceof SilencedErrorContext) { |
222 return true; | 222 return true; |
223 } | 223 } |
224 | 224 |
225 if ($exception instanceof \ErrorException && in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) { | 225 if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [E_DEPRECATED, E_USER_DEPRECATED], true)) { |
226 return true; | 226 return true; |
227 } | 227 } |
228 | 228 |
229 return false; | 229 return false; |
230 } | 230 } |
231 | 231 |
232 private function computeErrorsCount(array $containerDeprecationLogs) | 232 private function computeErrorsCount(array $containerDeprecationLogs) |
233 { | 233 { |
234 $silencedLogs = array(); | 234 $silencedLogs = []; |
235 $count = array( | 235 $count = [ |
236 'error_count' => $this->logger->countErrors(), | 236 'error_count' => $this->logger->countErrors(), |
237 'deprecation_count' => 0, | 237 'deprecation_count' => 0, |
238 'warning_count' => 0, | 238 'warning_count' => 0, |
239 'scream_count' => 0, | 239 'scream_count' => 0, |
240 'priorities' => array(), | 240 'priorities' => [], |
241 ); | 241 ]; |
242 | 242 |
243 foreach ($this->logger->getLogs() as $log) { | 243 foreach ($this->logger->getLogs() as $log) { |
244 if (isset($count['priorities'][$log['priority']])) { | 244 if (isset($count['priorities'][$log['priority']])) { |
245 ++$count['priorities'][$log['priority']]['count']; | 245 ++$count['priorities'][$log['priority']]['count']; |
246 } else { | 246 } else { |
247 $count['priorities'][$log['priority']] = array( | 247 $count['priorities'][$log['priority']] = [ |
248 'count' => 1, | 248 'count' => 1, |
249 'name' => $log['priorityName'], | 249 'name' => $log['priorityName'], |
250 ); | 250 ]; |
251 } | 251 } |
252 if ('WARNING' === $log['priorityName']) { | 252 if ('WARNING' === $log['priorityName']) { |
253 ++$count['warning_count']; | 253 ++$count['warning_count']; |
254 } | 254 } |
255 | 255 |