1111use Monolog \Handler \AbstractProcessingHandler ;
1212use Monolog \Logger ;
1313
14+ /**
15+ * @phpstan-import-type FormattedRecord from AbstractProcessingHandler
16+ */
1417class CloudWatchLogsHandler extends AbstractProcessingHandler
1518{
1619 /**
@@ -38,12 +41,16 @@ class CloudWatchLogsHandler extends AbstractProcessingHandler
3841 private $ client ;
3942
4043 /**
41- * @var array
44+ * @var array{
45+ * batchSize: int,
46+ * group: string,
47+ * stream: string,
48+ * }
4249 */
4350 private $ options ;
4451
4552 /**
46- * @var array
53+ * @var array<array{message: string, timestamp: int|float}>
4754 */
4855 private $ buffer = [];
4956
@@ -78,15 +85,14 @@ class CloudWatchLogsHandler extends AbstractProcessingHandler
7885 * stream: string,
7986 * } $options
8087 * @param int|string $level
81- * @param bool $bubble
8288 *
8389 * @throws \InvalidArgumentException
8490 */
8591 public function __construct (
8692 CloudWatchLogsClient $ client ,
87- $ options ,
93+ array $ options ,
8894 $ level = Logger::DEBUG ,
89- $ bubble = true
95+ bool $ bubble = true
9096 ) {
9197 $ options ['batchSize ' ] = $ options ['batchSize ' ] ?? 10000 ;
9298
@@ -123,8 +129,6 @@ protected function getDefaultFormatter(): FormatterInterface
123129
124130 /**
125131 * {@inheritdoc}
126- *
127- * @phpstan-ignore-next-line
128132 */
129133 protected function write (array $ record ): void
130134 {
@@ -183,6 +187,10 @@ private function flushBuffer(): void
183187 /**
184188 * Event size in the batch can not be bigger than 256 KB
185189 * 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}>
186194 */
187195 private function formatRecords (array $ entry ): array
188196 {
@@ -203,9 +211,9 @@ private function formatRecords(array $entry): array
203211 /**
204212 * http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html.
205213 *
206- * @param array $record
214+ * @param array{message: string, timestamp: int|float} $record
207215 */
208- private function getMessageSize ($ record ): int
216+ private function getMessageSize (array $ record ): int
209217 {
210218 return \strlen ($ record ['message ' ]) + 26 ;
211219 }
@@ -220,6 +228,8 @@ private function getMessageSize($record): int
220228 * expressed as the number of milliseconds since Jan 1, 1970 00:00:00 UTC).
221229 * - The maximum number of log events in a batch is 10,000.
222230 * - 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
223233 */
224234 private function send (array $ entries ): void
225235 {
0 commit comments