1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace PTS\LogsAggregator; |
5
|
|
|
|
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
|
8
|
|
|
class LogsAggregator implements LoggerInterface |
9
|
|
|
{ |
10
|
|
|
public const DEBUG = 100; |
11
|
|
|
public const INFO = 200; |
12
|
|
|
public const NOTICE = 250; |
13
|
|
|
public const WARNING = 300; |
14
|
|
|
public const ERROR = 400; |
15
|
|
|
public const CRITICAL = 500; |
16
|
|
|
public const ALERT = 550; |
17
|
|
|
public const EMERGENCY = 600; |
18
|
|
|
|
19
|
|
|
/** @var array */ |
20
|
|
|
protected $records = []; |
21
|
|
|
|
22
|
1 |
|
public function addRecord(int $level, string $message, array $context = []): void |
23
|
|
|
{ |
24
|
1 |
|
$this->records[] = [ |
25
|
1 |
|
'level' => $level, |
26
|
1 |
|
'message' => $message, |
27
|
1 |
|
'context' => $context, |
28
|
|
|
]; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
1 |
|
public function getRecords(): array |
35
|
|
|
{ |
36
|
1 |
|
return $this->records; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
public function reset(): void |
40
|
|
|
{ |
41
|
1 |
|
$this->records = []; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
1 |
|
public function emergency($message, array $context = []): void |
48
|
|
|
{ |
49
|
1 |
|
$this->addRecord(self::EMERGENCY, (string)$message, $context); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
1 |
|
public function alert($message, array $context = []): void |
56
|
|
|
{ |
57
|
1 |
|
$this->addRecord(self::ALERT, (string)$message, $context); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
1 |
|
public function critical($message, array $context = []): void |
64
|
|
|
{ |
65
|
1 |
|
$this->addRecord(self::CRITICAL, (string)$message, $context); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
1 |
|
public function error($message, array $context = []): void |
72
|
|
|
{ |
73
|
1 |
|
$this->addRecord(self::ERROR, (string)$message, $context); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
1 |
|
public function warning($message, array $context = []): void |
80
|
|
|
{ |
81
|
1 |
|
$this->addRecord(self::WARNING, (string)$message, $context); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
1 |
|
public function notice($message, array $context = []): void |
88
|
|
|
{ |
89
|
1 |
|
$this->addRecord(self::NOTICE, (string)$message, $context); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
1 |
|
public function info($message, array $context = []): void |
96
|
|
|
{ |
97
|
1 |
|
$this->addRecord(self::INFO, (string)$message, $context); |
98
|
1 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
1 |
|
public function debug($message, array $context = []): void |
104
|
|
|
{ |
105
|
1 |
|
$this->addRecord(self::DEBUG, (string)$message, $context); |
106
|
1 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
1 |
|
public function log($level, $message, array $context = []): void |
112
|
|
|
{ |
113
|
1 |
|
$this->addRecord($level, (string)$message, $context); |
114
|
1 |
|
} |
115
|
|
|
} |
116
|
|
|
|