11
11
use Monolog \Handler \AbstractProcessingHandler ;
12
12
use Monolog \Logger ;
13
13
14
+ /**
15
+ * @phpstan-import-type FormattedRecord from AbstractProcessingHandler
16
+ */
14
17
class CloudWatchLogsHandler extends AbstractProcessingHandler
15
18
{
16
19
/**
@@ -38,12 +41,16 @@ class CloudWatchLogsHandler extends AbstractProcessingHandler
38
41
private $ client ;
39
42
40
43
/**
41
- * @var array
44
+ * @var array{
45
+ * batchSize: int,
46
+ * group: string,
47
+ * stream: string,
48
+ * }
42
49
*/
43
50
private $ options ;
44
51
45
52
/**
46
- * @var array
53
+ * @var array<array{message: string, timestamp: int|float}>
47
54
*/
48
55
private $ buffer = [];
49
56
@@ -78,15 +85,14 @@ class CloudWatchLogsHandler extends AbstractProcessingHandler
78
85
* stream: string,
79
86
* } $options
80
87
* @param int|string $level
81
- * @param bool $bubble
82
88
*
83
89
* @throws \InvalidArgumentException
84
90
*/
85
91
public function __construct (
86
92
CloudWatchLogsClient $ client ,
87
- $ options ,
93
+ array $ options ,
88
94
$ level = Logger::DEBUG ,
89
- $ bubble = true
95
+ bool $ bubble = true
90
96
) {
91
97
$ options ['batchSize ' ] = $ options ['batchSize ' ] ?? 10000 ;
92
98
@@ -123,8 +129,6 @@ protected function getDefaultFormatter(): FormatterInterface
123
129
124
130
/**
125
131
* {@inheritdoc}
126
- *
127
- * @phpstan-ignore-next-line
128
132
*/
129
133
protected function write (array $ record ): void
130
134
{
@@ -183,6 +187,10 @@ private function flushBuffer(): void
183
187
/**
184
188
* Event size in the batch can not be bigger than 256 KB
185
189
* https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html.
190
+ *
191
+ * @phpstan-param FormattedRecord $entry
192
+ *
193
+ * @return list<array{message: string, timestamp: int|float}>
186
194
*/
187
195
private function formatRecords (array $ entry ): array
188
196
{
@@ -203,9 +211,9 @@ private function formatRecords(array $entry): array
203
211
/**
204
212
* http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html.
205
213
*
206
- * @param array $record
214
+ * @param array{message: string, timestamp: int|float} $record
207
215
*/
208
- private function getMessageSize ($ record ): int
216
+ private function getMessageSize (array $ record ): int
209
217
{
210
218
return \strlen ($ record ['message ' ]) + 26 ;
211
219
}
@@ -220,6 +228,8 @@ private function getMessageSize($record): int
220
228
* expressed as the number of milliseconds since Jan 1, 1970 00:00:00 UTC).
221
229
* - The maximum number of log events in a batch is 10,000.
222
230
* - A batch of log events in a single request cannot span more than 24 hours. Otherwise, the operation fails.
231
+ *
232
+ * @param array<array{message: string, timestamp: int|float}> $entries
223
233
*/
224
234
private function send (array $ entries ): void
225
235
{
0 commit comments