Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
6 / 9 |
|
62.50% |
5 / 8 |
CRAP | |
0.00% |
0 / 1 |
MultiLogger | |
66.67% |
6 / 9 |
|
62.50% |
5 / 8 |
12.00 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
logImpl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
log | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
trace | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
debug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
info | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
warn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
error | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Log; |
6 | |
7 | use PeServer\Core\Log\ILogger; |
8 | use PeServer\Core\Log\LoggerBase; |
9 | |
10 | /** |
11 | * 複数出力ロガー。 |
12 | */ |
13 | final class MultiLogger implements ILogger |
14 | { |
15 | /** |
16 | * 生成。 |
17 | * |
18 | * @param int $baseTraceIndex |
19 | * @phpstan-param non-negative-int $baseTraceIndex |
20 | * @param ILogger[] $loggers ロガー一覧。 |
21 | */ |
22 | public function __construct( |
23 | private readonly int $baseTraceIndex, |
24 | private readonly array $loggers |
25 | ) { |
26 | //NOP |
27 | } |
28 | |
29 | #region function |
30 | |
31 | /** |
32 | * 横流し処理。 |
33 | * |
34 | * @param int $level レベル。 |
35 | * @phpstan-param ILogger::LOG_LEVEL_* $level |
36 | * @param int $level |
37 | * @param int $traceIndex |
38 | * @phpstan-param non-negative-int $traceIndex |
39 | * @param mixed $message |
40 | * @phpstan-param LogMessageAlias $message |
41 | * @param mixed ...$parameters |
42 | */ |
43 | private function logImpl(int $level, int $traceIndex, $message, ...$parameters): void |
44 | { |
45 | foreach ($this->loggers as $logger) { |
46 | $logger->log($level, $traceIndex + 1, $message, ...$parameters); |
47 | } |
48 | } |
49 | |
50 | #endregion |
51 | |
52 | #region ILogger |
53 | |
54 | public function log(int $level, int $traceIndex, $message, ...$parameters): void |
55 | { |
56 | $this->logImpl($level, $traceIndex + 1, $message, ...$parameters); |
57 | } |
58 | |
59 | public function trace($message, ...$parameters): void |
60 | { |
61 | $this->logImpl(ILogger::LOG_LEVEL_TRACE, $this->baseTraceIndex + 1, $message, ...$parameters); |
62 | } |
63 | public function debug($message, ...$parameters): void |
64 | { |
65 | $this->logImpl(ILogger::LOG_LEVEL_DEBUG, $this->baseTraceIndex + 1, $message, ...$parameters); |
66 | } |
67 | public function info($message, ...$parameters): void |
68 | { |
69 | $this->logImpl(ILogger::LOG_LEVEL_INFORMATION, $this->baseTraceIndex + 1, $message, ...$parameters); |
70 | } |
71 | public function warn($message, ...$parameters): void |
72 | { |
73 | $this->logImpl(ILogger::LOG_LEVEL_WARNING, $this->baseTraceIndex + 1, $message, ...$parameters); |
74 | } |
75 | public function error($message, ...$parameters): void |
76 | { |
77 | $this->logImpl(ILogger::LOG_LEVEL_ERROR, $this->baseTraceIndex + 1, $message, ...$parameters); |
78 | } |
79 | |
80 | #endregion |
81 | } |