Skip to content

Added LogRecord to support L10 with Monolog 3.0 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": ">=7.2",
"laravel/framework": "7.0 || ^8.0 || ^9.0 || ^10.0",
"monolog/monolog": "2.*"
"monolog/monolog": "2.* || 3.*"
},
"license": "MIT",
"authors": [
Expand Down
5 changes: 3 additions & 2 deletions src/TelegramLoggerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Monolog\LogRecord;
use RLaurindo\TelegramLogger\Services\TelegramService;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public function __construct(string $logLevel)
* @param array $record
* @return void
*/
protected function write(array $record): void
protected function write(LogRecord $record): void
Copy link

@Pal9yni4bi Pal9yni4bi Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It breaks compatibility with monolog 2.* (it has such interface, but it hasn't implementation), so it's needed to remove it from compatible packages in composer.json. As well, as Laravel 7-9, that requires monolog 2.*.

Or it could be changed to array|LogRecord, but it'll break compatibility with Laravel before 9, cause union types is php8 feature.

{
$this->telegramService->sendMessage($this->formatLogText($record));
}
Expand All @@ -68,7 +69,7 @@ protected function write(array $record): void
* @var array $log
* @return string
*/
protected function formatLogText(array $log): string
protected function formatLogText(LogRecord $log): string
{
$logText = '<b>Application:</b> ' . $this->applicationName . PHP_EOL;
$logText .= '<b>Environment:</b> ' . $this->applicationEnvironment . PHP_EOL;
Expand Down