From d10ee332155da7bf08efdec2b352fd0e5feff8dc Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 6 Jun 2025 17:55:58 -0400 Subject: [PATCH] better format for mysql --- app/common/Implement/Log/Formatter/PDO.php | 29 ++++++++++++++++++++++ cli/src/Service/Job.php | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/common/Implement/Log/Formatter/PDO.php b/app/common/Implement/Log/Formatter/PDO.php index 64662ba..7096e39 100644 --- a/app/common/Implement/Log/Formatter/PDO.php +++ b/app/common/Implement/Log/Formatter/PDO.php @@ -1,6 +1,7 @@ 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; + } } diff --git a/cli/src/Service/Job.php b/cli/src/Service/Job.php index c017c1f..897721b 100644 --- a/cli/src/Service/Job.php +++ b/cli/src/Service/Job.php @@ -2,8 +2,8 @@ namespace Incoviba\Service; use Exception; -use Predis\Connection\ConnectionException; use Psr\Log\LoggerInterface; +use Predis\Connection\ConnectionException; class Job {