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