better format for mysql

This commit is contained in:
Juan Pablo Vial
2025-06-06 17:55:58 -04:00
parent 5134630525
commit d10ee33215
2 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace Incoviba\Common\Implement\Log\Formatter;
use Throwable;
use Monolog\Formatter\JsonFormatter;
use Monolog\LogRecord;
@ -13,7 +14,35 @@ class PDO extends JsonFormatter
public function format(LogRecord $record): string
{
if (is_a($record->message, Throwable::class)) {
$exception = $record->message;
$message = $this->normalizeException($exception);
$context = $record->context;
$context['exception'] = $exception;
if ($exception->getPrevious()) {
$context['previous'] = $this->walkException($exception);
}
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
json_encode($message),
$context,
$record->extra
);
$record = $new_record;
}
$normalized = $this->normalize($record, $this->maxNormalizeDepth);
return $normalized['message'];
}
protected function walkException(Throwable $exception, int $depth = 0): array
{
$output = [];
$currentDepth = $depth;
while ($previous = $exception->getPrevious() and $currentDepth < $this->maxNormalizeDepth) {
$output []= $this->normalizeException($previous);
}
return $output;
}
}

View File

@ -2,8 +2,8 @@
namespace Incoviba\Service;
use Exception;
use Predis\Connection\ConnectionException;
use Psr\Log\LoggerInterface;
use Predis\Connection\ConnectionException;
class Job
{