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