|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Collector; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use Psr\Log\LogLevel; |
|
9
|
|
|
use Stringable; |
|
10
|
|
|
|
|
11
|
|
|
final class LoggerInterfaceProxy implements LoggerInterface |
|
12
|
|
|
{ |
|
13
|
|
|
public function __construct( |
|
14
|
|
|
private readonly LoggerInterface $logger, |
|
15
|
|
|
private readonly LogCollector $collector |
|
16
|
16 |
|
) { |
|
17
|
|
|
} |
|
18
|
16 |
|
|
|
19
|
16 |
|
public function emergency(string|Stringable $message, array $context = []): void |
|
20
|
|
|
{ |
|
21
|
|
|
$callStack = $this->getCallStack(); |
|
22
|
1 |
|
|
|
23
|
|
|
$this->collector->collect( |
|
24
|
1 |
|
LogLevel::EMERGENCY, |
|
25
|
|
|
$message, |
|
26
|
1 |
|
$context, |
|
27
|
|
|
$callStack['file'] . ':' . $callStack['line'] |
|
28
|
|
|
); |
|
29
|
|
|
$this->logger->emergency($message, $context); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function alert(string|Stringable $message, array $context = []): void |
|
33
|
|
|
{ |
|
34
|
|
|
$callStack = $this->getCallStack(); |
|
35
|
1 |
|
|
|
36
|
|
|
$this->collector->collect(LogLevel::ALERT, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
37
|
1 |
|
$this->logger->alert($message, $context); |
|
38
|
|
|
} |
|
39
|
1 |
|
|
|
40
|
1 |
|
public function critical(string|Stringable $message, array $context = []): void |
|
41
|
|
|
{ |
|
42
|
|
|
$callStack = $this->getCallStack(); |
|
43
|
1 |
|
|
|
44
|
|
|
$this->collector->collect( |
|
45
|
1 |
|
LogLevel::CRITICAL, |
|
46
|
|
|
$message, |
|
47
|
1 |
|
$context, |
|
48
|
|
|
$callStack['file'] . ':' . $callStack['line'] |
|
49
|
|
|
); |
|
50
|
|
|
$this->logger->critical($message, $context); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function error(string|Stringable $message, array $context = []): void |
|
54
|
|
|
{ |
|
55
|
|
|
$callStack = $this->getCallStack(); |
|
56
|
1 |
|
|
|
57
|
|
|
$this->collector->collect(LogLevel::ERROR, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
58
|
1 |
|
$this->logger->error($message, $context); |
|
59
|
|
|
} |
|
60
|
1 |
|
|
|
61
|
1 |
|
public function warning(string|Stringable $message, array $context = []): void |
|
62
|
|
|
{ |
|
63
|
|
|
$callStack = $this->getCallStack(); |
|
64
|
1 |
|
|
|
65
|
|
|
$this->collector->collect(LogLevel::WARNING, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
66
|
1 |
|
$this->logger->warning($message, $context); |
|
67
|
|
|
} |
|
68
|
1 |
|
|
|
69
|
1 |
|
public function notice(string|Stringable $message, array $context = []): void |
|
70
|
|
|
{ |
|
71
|
|
|
$callStack = $this->getCallStack(); |
|
72
|
|
|
|
|
73
|
|
|
$this->collector->collect(LogLevel::NOTICE, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
74
|
|
|
$this->logger->notice($message, $context); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function info(string|Stringable $message, array $context = []): void |
|
78
|
|
|
{ |
|
79
|
|
|
$callStack = $this->getCallStack(); |
|
80
|
1 |
|
|
|
81
|
|
|
$this->collector->collect(LogLevel::INFO, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
82
|
1 |
|
$this->logger->info($message, $context); |
|
83
|
|
|
} |
|
84
|
1 |
|
|
|
85
|
1 |
|
public function debug(string|Stringable $message, array $context = []): void |
|
86
|
|
|
{ |
|
87
|
|
|
$callStack = $this->getCallStack(); |
|
88
|
1 |
|
|
|
89
|
|
|
$this->collector->collect(LogLevel::DEBUG, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
90
|
1 |
|
$this->logger->debug($message, $context); |
|
91
|
|
|
} |
|
92
|
1 |
|
|
|
93
|
1 |
|
public function log(mixed $level, string|Stringable $message, array $context = []): void |
|
94
|
|
|
{ |
|
95
|
|
|
$callStack = $this->getCallStack(); |
|
96
|
8 |
|
|
|
97
|
|
|
$this->collector->collect($level, $message, $context, $callStack['file'] . ':' . $callStack['line']); |
|
98
|
8 |
|
$this->logger->log($level, $message, $context); |
|
99
|
|
|
} |
|
100
|
8 |
|
|
|
101
|
8 |
|
/** |
|
102
|
|
|
* @psalm-return array{file: string, line: int} |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getCallStack(): array |
|
105
|
|
|
{ |
|
106
|
|
|
/** @psalm-var array{file: string, line: int} */ |
|
107
|
|
|
return debug_backtrace()[1]; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|