Skip to content

Commit 7c8b145

Browse files
committed
feat: reduce trace length
1 parent 390276d commit 7c8b145

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/ExceptionCatcher/TraceOfExceptionProcessor.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ public function __invoke(LogRecord $record): LogRecord
2424
$context['exception']['data'] = \json_encode($exception, \JSON_THROW_ON_ERROR);
2525
}
2626

27-
if (true === \array_key_exists('trace', $context['exception'])) {
28-
$context['exception']['trace'] = \json_encode(
29-
$context['exception']['trace'],
30-
\JSON_THROW_ON_ERROR,
31-
);
32-
}
33-
3427
return new LogRecord(
3528
$record->datetime,
3629
$record->channel,

src/Util/AssocSerializer.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,34 @@ private static function throwable(\Throwable $throwable): array
3333
'code' => $throwable->getCode(),
3434
'file' => $throwable->getFile(),
3535
'line' => $throwable->getLine(),
36-
'trace' => $throwable->getTraceAsString(),
36+
'trace' => self::trace($throwable),
3737
];
3838
}
3939

40+
private static function trace(\Throwable $throwable): string
41+
{
42+
$trace = $throwable->getTrace();
43+
$traceLenght = \count($trace);
44+
$pagLenght = \strlen((string)$traceLenght);
45+
46+
$result = [];
47+
48+
foreach ($trace as $key => $step) {
49+
$result[] = \sprintf(
50+
"#%s %s(%s)%s%s()",
51+
\str_pad((string)$key, $pagLenght, '0', \STR_PAD_LEFT),
52+
$step['file'] ?? '',
53+
$step['line'] ?? '',
54+
$step['type'] ?? '',
55+
$step['function'] ?? '',
56+
);
57+
}
58+
59+
return \implode(\PHP_EOL, $result);
60+
}
61+
4062
private static function basic($anything): array
4163
{
42-
return \json_decode(
43-
\json_encode($anything),
44-
true,
45-
);
64+
return \json_decode(\json_encode($anything), true);
4665
}
4766
}

0 commit comments

Comments
 (0)