leek/laravel-compact-logs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

leek/laravel-compact-logs

Composer 安装命令:

composer require leek/laravel-compact-logs

包简介

Truncate verbose stack traces in Laravel log files for cleaner, more readable logs.

README 文档

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_depth frames (default: 3)
  • A ... and N more frames indicator shows how many were omitted
  • Previous exception chains are also truncated
  • All other log formatting remains unchanged

License

MIT

统计信息

  • 总下载量: 2.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固