1 | <?php declare(strict_types=1); |
||
16 | abstract class AbstractLogglyLogger extends AbstractLogger |
||
17 | { |
||
18 | 2 | public function log($level, $message, array $context = []): void |
|
19 | { |
||
20 | 2 | checkCorrectLogLevel($level); |
|
21 | $this->send( |
||
22 | $this->format($level, $message, $context) |
||
23 | ); |
||
24 | } |
||
25 | |||
26 | abstract protected function send(string $data); |
||
27 | |||
28 | protected function format($level, $message, array $context): string |
||
29 | { |
||
30 | $message = (string)$message; |
||
31 | $context = normalizeContextWithFormatValue($context); |
||
32 | $message = processPlaceHolders($message, $context); |
||
33 | $json = \json_encode([ |
||
34 | 'level' => $level, |
||
35 | 'message' => $level . ' ' . $message, |
||
36 | 'context' => $context, |
||
37 | ]); |
||
38 | |||
39 | if ($json === false) { |
||
40 | throw new InvalidArgumentException(\json_last_error_msg()); |
||
41 | } |
||
42 | |||
43 | return $json; |
||
44 | } |
||
45 | |||
46 | 4 | protected static function createHttpClient(LoopInterface $loop): Client |
|
67 | } |
||
68 |