Skip to content

Commit

Permalink
Fix log formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
punyflash committed Jun 28, 2023
1 parent c00ad32 commit fa70e8c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Laravel/Log/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Monolog\LogRecord;
use WeStacks\TeleBot\TeleBot;

class Handler extends AbstractProcessingHandler
Expand Down Expand Up @@ -53,7 +54,7 @@ public function __construct(array $config)
$this->env = config('app.env');
}

public function write(array $record): void
public function write(LogRecord|array $record): void
{
$textChunks = str_split($this->formatText($record), 4096);

Expand All @@ -70,8 +71,12 @@ protected function getDefaultFormatter(): FormatterInterface
return new LineFormatter("%message% %context% %extra%\n");
}

private function formatText(array $record): string
private function formatText(LogRecord|array $record): string
{
if (is_a($record, LogRecord::class)) {
$record = array_merge($record->toArray(), ['formatted' => $record->formatted]);
}

return view('telebot::log', array_merge($record, [
'app' => $this->app,
'env' => $this->env,
Expand Down

0 comments on commit fa70e8c

Please sign in to comment.