diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index ec1ca054..037dea16 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,4 +1,4 @@ -blank_issues_enabled: false +blank_issues_enabled: true contact_links: - name: Ask a question url: https://github.com/opcodesio/log-viewer/discussions/new?category=q-a diff --git a/.gitignore b/.gitignore index 772e1015..441f5b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,13 +3,13 @@ .phpunit.result.cache .phpunit.cache build -composer.lock -coverage -docs -logs +/composer.lock +/coverage +/docs +/logs phpunit.xml phpstan.neon testbench.yaml -vendor -node_modules -tests/Feature/performance_test.log +/vendor +/node_modules +/tests/Feature/performance_test.log diff --git a/src/Logs/LaravelLog.php b/src/Logs/LaravelLog.php index e6e48060..707ecf5f 100644 --- a/src/Logs/LaravelLog.php +++ b/src/Logs/LaravelLog.php @@ -108,8 +108,8 @@ protected function extractContextsFromFullText(): void $json_data = json_decode(trim($json_string), true); if (json_last_error() == JSON_ERROR_CTRL_CHAR) { - // might need to escape new lines - $json_data = json_decode(str_replace("\n", '\\n', $json_string), true); + // might need to escape new lines and carriage returns + $json_data = json_decode(str_replace(["\r\n", "\r", "\n"], ['\\n', '\\n', '\\n'], $json_string), true); } if (json_last_error() == JSON_ERROR_NONE) { @@ -193,6 +193,10 @@ protected function getJsonStringsFromFullText(): array protected function filterStackTrace(string $text): string { + // Normalize line endings for cross-platform compatibility + $text = str_replace("\r\n", "\n", $text); + $text = str_replace("\r", "\n", $text); + $lines = explode("\n", $text); $filteredLines = []; $emptyLineCharacter = ' ...'; diff --git a/tests/Unit/LaravelLogs/LaravelLogsTest.php b/tests/Unit/LaravelLogs/LaravelLogsTest.php index 65de5bcc..458e062a 100644 --- a/tests/Unit/LaravelLogs/LaravelLogsTest.php +++ b/tests/Unit/LaravelLogs/LaravelLogsTest.php @@ -255,3 +255,67 @@ 'size_formatted' => Utils::bytesForHumans(strlen($messageString) - strlen('[2023-08-24 15:51:14] local.DEBUG: ')), ]); }); + +it('filters stack traces in context when shorter stack traces is enabled', function () { + session(['log-viewer:shorter-stack-traces' => true]); + config([ + 'log-viewer.shorter_stack_trace_excludes' => [ + '/vendor/symfony/', + '/vendor/laravel/framework/', + ], + ]); + + $stackTrace = <<<'EOF' +#0 /app/Controllers/UserController.php(25): someFunction() +#1 /vendor/symfony/http-kernel/HttpKernel.php(158): handle() +#2 /vendor/laravel/framework/Illuminate/Pipeline/Pipeline.php(128): process() +#3 /app/Middleware/CustomMiddleware.php(42): handle() +#4 /vendor/symfony/routing/Router.php(89): route() +#5 /app/bootstrap/app.php(15): bootstrap() +EOF; + + $logText = <<context)->toHaveKey('exception') + ->and($log->context['exception'])->toContain('#0 /app/Controllers/UserController.php(25): someFunction()') + ->and($log->context['exception'])->toContain('#3 /app/Middleware/CustomMiddleware.php(42): handle()') + ->and($log->context['exception'])->toContain('#5 /app/bootstrap/app.php(15): bootstrap()') + ->and($log->context['exception'])->toContain(' ...') + ->and($log->context['exception'])->not->toContain('/vendor/symfony/http-kernel/') + ->and($log->context['exception'])->not->toContain('/vendor/laravel/framework/') + ->and($log->context['exception'])->not->toContain('/vendor/symfony/routing/'); +}); + +it('does not filter context when shorter stack traces is disabled', function () { + session(['log-viewer:shorter-stack-traces' => false]); + config([ + 'log-viewer.shorter_stack_trace_excludes' => [ + '/vendor/symfony/', + '/vendor/laravel/framework/', + ], + ]); + + $stackTrace = <<<'EOF' +#0 /app/Controllers/UserController.php(25): someFunction() +#1 /vendor/symfony/http-kernel/HttpKernel.php(158): handle() +#2 /vendor/laravel/framework/Illuminate/Pipeline/Pipeline.php(128): process() +EOF; + + $logText = <<context)->toHaveKey('exception') + ->and($log->context['exception'])->toBe($expectedStackTrace) + ->and($log->context['exception'])->toContain('/vendor/symfony/http-kernel/') + ->and($log->context['exception'])->toContain('/vendor/laravel/framework/'); +});