1 | <?php |
||
31 | abstract class AbstractLogger |
||
32 | { |
||
33 | /** @var string */ |
||
34 | protected $format = "%s:%s.%s"; |
||
35 | |||
36 | /** @var LoggerInterface */ |
||
37 | protected static $logger; |
||
38 | |||
39 | /** |
||
40 | * @param LoggableAnnotate $annotation |
||
41 | * @param MethodInvocation $invocation |
||
42 | * @return array |
||
43 | * @throws \ReflectionException |
||
44 | */ |
||
45 | protected function logFormatter( |
||
46 | LoggableAnnotate $annotation, |
||
47 | MethodInvocation $invocation |
||
48 | ): array { |
||
49 | $context = []; |
||
50 | $arguments = $invocation->getArguments(); |
||
51 | foreach ($invocation->getMethod()->getParameters() as $parameter) { |
||
52 | $context['args'][$parameter->name] = isset($arguments[$parameter->getPosition()]) ? |
||
53 | $arguments[$parameter->getPosition()] : |
||
54 | ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null); |
||
55 | } |
||
56 | |||
57 | return [ |
||
58 | 'level' => $annotation->value, |
||
59 | 'message' => sprintf( |
||
60 | $this->format, |
||
61 | $annotation->name, |
||
62 | $invocation->getMethod()->class, |
||
63 | $invocation->getMethod()->name |
||
64 | ), |
||
65 | 'context' => $context, |
||
66 | ]; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param LoggerInterface $logger |
||
71 | */ |
||
72 | public function setLogger(LoggerInterface $logger): void |
||
76 | } |
||
77 |