|
10 | 10 | use Psr\Log\LogLevel; |
11 | 11 | use Throwable; |
12 | 12 |
|
13 | | -use function get_class; |
14 | | - |
15 | 13 | /** |
16 | 14 | * Formatter that includes the Command's name and properties for more detail |
17 | 15 | */ |
18 | 16 | class ClassPropertiesFormatter implements Formatter |
19 | 17 | { |
20 | 18 | private PropertyNormalizer $normalizer; |
21 | 19 |
|
22 | | - private string $commandReceivedLevel; |
23 | | - |
24 | | - private string $commandSucceededLevel; |
25 | | - |
26 | | - private string $commandFailedLevel; |
27 | | - |
28 | 20 | public function __construct( |
29 | | - ?PropertyNormalizer $normalizer = null, |
30 | | - string $commandReceivedLevel = LogLevel::DEBUG, |
31 | | - string $commandSucceededLevel = LogLevel::DEBUG, |
32 | | - string $commandFailedLevel = LogLevel::ERROR |
| 21 | + PropertyNormalizer|null $normalizer = null, |
| 22 | + private string $commandReceivedLevel = LogLevel::DEBUG, |
| 23 | + private string $commandSucceededLevel = LogLevel::DEBUG, |
| 24 | + private string $commandFailedLevel = LogLevel::ERROR, |
33 | 25 | ) { |
34 | | - $this->normalizer = $normalizer ?: new SimplePropertyNormalizer(); |
35 | | - $this->commandReceivedLevel = $commandReceivedLevel; |
36 | | - $this->commandSucceededLevel = $commandSucceededLevel; |
37 | | - $this->commandFailedLevel = $commandFailedLevel; |
| 26 | + $this->normalizer = $normalizer ?: new SimplePropertyNormalizer(); |
38 | 27 | } |
39 | 28 |
|
40 | 29 | public function logCommandReceived(LoggerInterface $logger, object $command): void |
41 | 30 | { |
42 | 31 | $logger->log( |
43 | 32 | $this->commandReceivedLevel, |
44 | | - 'Command received: ' . get_class($command), |
45 | | - ['command' => $this->normalizer->normalize($command)] |
| 33 | + 'Command received: ' . $command::class, |
| 34 | + ['command' => $this->normalizer->normalize($command)], |
46 | 35 | ); |
47 | 36 | } |
48 | 37 |
|
49 | | - /** |
50 | | - * {@inheritDoc} |
51 | | - */ |
52 | | - public function logCommandSucceeded(LoggerInterface $logger, object $command, $returnValue): void |
| 38 | + public function logCommandSucceeded(LoggerInterface $logger, object $command, mixed $returnValue): void |
53 | 39 | { |
54 | 40 | $logger->log( |
55 | 41 | $this->commandSucceededLevel, |
56 | | - 'Command succeeded: ' . get_class($command), |
| 42 | + 'Command succeeded: ' . $command::class, |
57 | 43 | [ |
58 | 44 | 'command' => $this->normalizer->normalize($command), |
59 | | - ] |
| 45 | + ], |
60 | 46 | ); |
61 | 47 | } |
62 | 48 |
|
63 | 49 | public function logCommandFailed(LoggerInterface $logger, object $command, Throwable $e): void |
64 | 50 | { |
65 | 51 | $logger->log( |
66 | 52 | $this->commandFailedLevel, |
67 | | - 'Command failed: ' . get_class($command), |
68 | | - ['exception' => $e] |
| 53 | + 'Command failed: ' . $command::class, |
| 54 | + ['exception' => $e], |
69 | 55 | ); |
70 | 56 | } |
71 | 57 | } |
0 commit comments