Skip to content

Commit

Permalink
php8.0 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rezafarzaneh7 committed Dec 13, 2023
1 parent 1da3c30 commit c0b20c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"source": "https://github.com/useinsider/cwh"
},
"require": {
"php": ">=8.1",
"monolog/monolog": "^3.0",
"php": "^7.2 || ^8",
"monolog/monolog": "^2.0",
"aws/aws-sdk-php": "^3.2"
},
"require-dev": {
Expand Down
33 changes: 16 additions & 17 deletions src/Handler/CloudWatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
use Monolog\Level;

class CloudWatch extends AbstractProcessingHandler
{
Expand Down Expand Up @@ -44,7 +42,7 @@ class CloudWatch extends AbstractProcessingHandler
private int $currentDataAmount = 0;
private int $remainingRequests;
private \DateTimeImmutable $savedTime;
private int | null $earliestTimestamp = null;
private int|null $earliestTimestamp = null;

/**
* CloudWatchLogs constructor.
Expand All @@ -61,17 +59,18 @@ class CloudWatch extends AbstractProcessingHandler
*/
public function __construct(
CloudWatchLogsClient $client,
string $group,
string $stream,
int $retention = 14,
int $batchSize = 10000,
array $tags = [],
int | string | Level $level = Level::Debug,
bool $bubble = true,
bool $createGroup = true,
bool $createStream = true,
int $rpsLimit = 0
) {
string $group,
string $stream,
int $retention = 14,
int $batchSize = 10000,
array $tags = [],
$level = Logger::DEBUG,
bool $bubble = true,
bool $createGroup = true,
bool $createStream = true,
int $rpsLimit = 0
)
{
if ($batchSize > 10000) {
throw new \InvalidArgumentException('Batch size can not be greater than 10000');
}
Expand All @@ -93,7 +92,7 @@ public function __construct(
$this->savedTime = new \DateTimeImmutable();
}

protected function write(LogRecord $record): void
protected function write(array $record): void
{
$records = $this->formatRecords($record);

Expand Down Expand Up @@ -204,7 +203,7 @@ protected function willMessageTimestampExceedLimit(array $record): bool
* Event size in the batch can not be bigger than 256 KB
* https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html
*/
private function formatRecords(LogRecord $entry): array
private function formatRecords(array $entry): array
{
$entries = str_split($entry['formatted'], self::EVENT_SIZE_LIMIT);
$timestamp = $entry['datetime']->format('U.u') * 1000;
Expand Down Expand Up @@ -332,7 +331,7 @@ private function initialize(): void

protected function getDefaultFormatter(): FormatterInterface
{
return new LineFormatter("%channel%: %level_name%: %message% %context% %extra%", null, false, true);
return new LineFormatter('%channel%: %level_name%: %message% %context% %extra%', null, false, true);
}

public function close(): void
Expand Down

0 comments on commit c0b20c1

Please sign in to comment.