leek / laravel-compact-logs
Truncate verbose stack traces in Laravel log files for cleaner, more readable logs.
Installs: 46
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/leek/laravel-compact-logs
Requires
- php: ^8.2
- illuminate/log: ^11.0|^12.0
- monolog/monolog: ^3.0
This package is auto-updated.
Last update: 2026-02-13 16:03:48 UTC
README
Truncate verbose stack traces in Laravel log files. Instead of 100+ line stack traces per error, get the error message and the first few relevant frames.
Before:
[2026-02-12 08:37:31] local.ERROR: Connection refused {"exception":"[object] (PDOException...)
[stacktrace]
#0 /vendor/laravel/framework/src/.../Connection.php(420): PDO->prepare(...)
#1 /vendor/laravel/framework/src/.../Connection.php(827): ...
#2 /vendor/laravel/framework/src/.../Connection.php(794): ...
#3 /vendor/laravel/framework/src/.../Connection.php(411): ...
... 80 more lines of framework internals ...
After:
[2026-02-12 08:37:31] local.ERROR: Connection refused {"exception":"[object] (PDOException...)
[stacktrace]
#0 /vendor/laravel/framework/src/.../Connection.php(420): PDO->prepare(...)
#1 /vendor/laravel/framework/src/.../Connection.php(827): ...
#2 /vendor/laravel/framework/src/.../Connection.php(794): ...
... and 80 more frames"}
Installation
composer require leek/laravel-compact-logs
That's it. The package auto-registers and applies to single and daily log channels by default.
Configuration
Publish the config file to customize:
php artisan vendor:publish --tag=compact-logs-config
// config/compact-logs.php return [ // Channels to apply truncation to (set to null to disable auto-registration) 'channels' => ['single', 'daily'], // Max stack trace frames per exception 'max_trace_depth' => (int) env('LOG_TRACE_DEPTH', 3), ];
Environment Variable
LOG_TRACE_DEPTH=5
Manual Setup
If you prefer manual control, set channels to null in the config and add the tap directly to your config/logging.php:
'single' => [ 'driver' => 'single', 'tap' => [\Leek\CompactLogs\CompactExceptionTap::class], 'path' => storage_path('logs/laravel.log'), 'level' => env('LOG_LEVEL', 'debug'), ],
How It Works
The package provides a custom Monolog LineFormatter that overrides normalizeException() to truncate stack traces. A logging tap applies this formatter to your configured channels.
- Stack traces are trimmed to
max_trace_depthframes (default: 3) - A
... and N more framesindicator shows how many were omitted - Previous exception chains are also truncated
- All other log formatting remains unchanged
License
MIT