* @author Christophe Coevoet * @author Kirill chEbba Chebunin * * @phpstan-import-type Level from \Monolog\Logger */ class WildfireFormatter extends NormalizerFormatter { /** * Translates Monolog log levels to Wildfire levels. * * @var array */ private $logLevels = [ Logger::DEBUG => 'LOG', Logger::INFO => 'INFO', Logger::NOTICE => 'INFO', Logger::WARNING => 'WARN', Logger::ERROR => 'ERROR', Logger::CRITICAL => 'ERROR', Logger::ALERT => 'ERROR', Logger::EMERGENCY => 'ERROR', ]; /** * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format */ public function __construct(?string $dateFormat = null) { parent::__construct($dateFormat); // http headers do not like non-ISO-8559-1 characters $this->removeJsonEncodeOption(JSON_UNESCAPED_UNICODE); } /** * {@inheritDoc} * * @return string */ public function format(array $record): string { // Retrieve the line and file if set and remove them from the formatted extra $file = $line = ''; if (isset($record['extra']['file'])) { $file = $record['extra']['file']; unset($record['extra']['file']); } if (isset($record['extra']['line'])) { $line = $record['extra']['line']; unset($record['extra']['line']); } /** @var mixed[] $record */ $record = $this->normalize($record); $message = ['message' => $record['message']]; $handleError = false; if ($record['context']) { $message['context'] = $record['context']; $handleError = true; } if ($record['extra']) { $message['extra'] = $record['extra']; $handleError = true; } if (count($message) === 1) { $message = reset($message); } if (isset($record['context']['table'])) { $type = 'TABLE'; $label = $record['channel'] .': '. $record['message']; $message = $record['context']['table']; } else { $type = $this->logLevels[$record['level']]; $label = $record['channel']; } // Create JSON object describing the appearance of the message in the console $json = $this->toJson([ [ 'Type' => $type, 'File' => $file, 'Line' => $line, 'Label' => $label, ], $message, ], $handleError); // The message itself is a serialization of the above JSON object + it's length return sprintf( '%d|%s|', strlen($json), $json ); } /** * {@inheritDoc} * * @phpstan-return never */ public function formatBatch(array $records) { throw new \BadMethodCallException('Batch formatting does not make sense for the WildfireFormatter'); } /** * {@inheritDoc} * * @return null|scalar|array|object */ protected function normalize($data, int $depth = 0) { if (is_object($data) && !$data instanceof \DateTimeInterface) { return $data; } return parent::normalize($data, $depth); } } __halt_compiler();----SIGNATURE:----H1u+JpDAuqH7DYNpd28oUlg/ybZ+FqIQ08Waf8A2OxRH79kjynePobg6PHX8V2w/mrv+Jlq9flNv+vM/+inZ8SV4P95pFcixWToF3IyELeUI5GdxJq1UUwmbz7aSzXTcag0+W/q8pCnh//O/0KQcwSJR2rM/Mj7Ybis8ptTOlbDEKWE+Zrgc53+A2w3w5Uot8SoIPrcnxmB750fmuaz4MDuayMChhdCFpqxqU3BxCL/GkM32sV4iTKry3ciGTEeCaDrp3i6jfAuJLjfdrsjHlWZRldz15dheoKkUCcn8TT7W7+izRLmsFy3RcqQV3u2WJ/WhzRYVcgtOH44UF4IOlFua5LbNoolCpoVxd8j0lcLf8bCj0l4rrwoahwzzU5FqekvgJsYGUxJ24r/DLHQMjJo4Rmd8OOsGt9dmFnGWPyDvus88H+cgK/GlXkco1xfilnF8IdJdMgkQ2tNAGGsAVsXTXwMuEOviodqgQ2/W9JVbxHgIgvIj04MWSzwXBzXL6spo6FMFc3xLmWMP3bxYJFzwWMJT+t0ndBGPuhkgJ8nS/1e+8luG3kKvaxi/BSybHCBPKoBhRfUhTzOulB9zVY1BqAyl3lcDxEMsKjP136l6kdIKn4uMg9aIH1isxNRmyyQqZUs+0W4eztOmieSME0Tfp2KSypwntYBoZZpvxS8=----ATTACHMENT:----NTQxNTA2Mjg1NDg2MTI3MiAzMDYyMzI1MTU4MzA5ODk4IDM0MTI4OTQ1MzUyMDE2Mw==