brrittoo/query-debug-tools
Composer 安装命令:
composer require brrittoo/query-debug-tools
包简介
Advanced Database Query Logging & Performance Monitor
README 文档
README
Effortlessly log, monitor, and debug all database queries in your Laravel applications with detailed execution insights, source tracking, and customizable storag
Features
- 📝 Comprehensive query logging with execution time tracking
- 🐌 Slow query detection with customizable threshold
- 📂 Configurable log storage and retention
- 🔍 Backtrace tracking to identify query origins
- 🖥️ Support for both web requests and console commands
- � Job/queue query logging support
- ⚙️ Flexible configuration options
- 📊 Multiple log formats (plain text or JSON)
Installation
Install via Composer:
composer require brrittoo/query-debug-tools
Publish the configuration file:
php artisan vendor:publish --provider="Brrittoo\QueryLogger\Providers\QueryLoggerServiceProvider" --tag="query-logger-config"
Configuration
The published configuration is located at config/querylogger.php:
return [ /* |-------------------------------------------------------------------------- | Query Logger Enable |-------------------------------------------------------------------------- | | Enable or disable query logging globally. | */ 'enabled' => env('QUERY_LOGGER_ENABLED', true), /* |-------------------------------------------------------------------------- | Query Logger Enable |-------------------------------------------------------------------------- | | Enable or disable query logging globally. | */ 'enable_generate_multiple_files_in_same_file' => env('QUERY_LOGGER_MULTIPLE_FILES', true), /* |-------------------------------------------------------------------------- | Log Retention Days |-------------------------------------------------------------------------- | | Number of days to keep log files before automatic deletion. | Set to 0 to disable automatic cleanup. | */ 'retention_days' => env('QUERY_LOGGER_RETENTION_DAYS', 15), /* |-------------------------------------------------------------------------- | Storage Path |-------------------------------------------------------------------------- | | Location where query log files will be stored. | */ 'storage_path' => storage_path('logs/querylog'), /* |-------------------------------------------------------------------------- | Slow Query Threshold |-------------------------------------------------------------------------- | | Only log queries slower than this threshold (in milliseconds). | Set to 0 to log all queries. | */ 'slow_query_threshold' => env('QUERY_LOGGER_SLOW_QUERY_THRESHOLD', 0), /* |-------------------------------------------------------------------------- | Log Format |-------------------------------------------------------------------------- | | Format of the log files: 'plain' or 'json'. | */ 'log_format' => env('QUERY_LOGGER_FORMAT', 'plain'), /* |-------------------------------------------------------------------------- | Middleware Configuration |-------------------------------------------------------------------------- | | Settings for automatic middleware registration. | */ 'middleware' => [ /* |---------------------------------------------------------------------- | Auto-Registered Middleware Groups |---------------------------------------------------------------------- | | Middleware groups where the query logger should be automatically | registered (e.g., 'web', 'api'). | */ 'enable_groups' => [ 'web', 'api' ], /* |---------------------------------------------------------------------- | Middleware Alias |---------------------------------------------------------------------- | | The alias to use when registering the middleware. | */ 'alias' => 'query.logger', /* |---------------------------------------------------------------------- | Excluded Routes |---------------------------------------------------------------------- | | Route names that should be excluded from logging. | */ 'exclude_routes' => [ 'login', 'health-check', 'horizon.*', 'telescope', 'debugbar.*' ], ], /* |-------------------------------------------------------------------------- | Backtrace |-------------------------------------------------------------------------- | | Whether to include the query origin backtrace. | */ 'log_backtrace' => env('QUERY_LOGGER_LOG_BACKTRACE', true), /* |-------------------------------------------------------------------------- | Max Backtrace Depth |-------------------------------------------------------------------------- | | Maximum number of backtrace frames to log. | */ 'backtrace_depth' => env('QUERY_LOGGER_BACKTRACE_DEPTH', 5), ];
Usage
Configuration
Set these in your .env:
| Variable | Default | Description | | ----------------------------------- | ------- | -------------------------------------------------------------------------------------- | | `QUERY_LOGGER_ENABLED` | `true` | Enable or disable query logging globally. | | `QUERY_LOGGER_MULTIPLE_FILES` | `true` | Generate multiple log files per day. Set `false` to append to a single daily log file. | | `QUERY_LOGGER_RETENTION_DAYS` | `15` | Number of days to keep old logs; older logs will be deleted automatically. | | `QUERY_LOGGER_SLOW_QUERY_THRESHOLD` | `1000` | Threshold in milliseconds to consider a query as slow. | | `QUERY_LOGGER_FORMAT` | `plain` | Log format: `plain` or `json`. | | `QUERY_LOGGER_LOG_BACKTRACE` | `false` | Enable logging of backtrace for each query. | | `QUERY_LOGGER_BACKTRACE_DEPTH` | `5` | Depth of backtrace to log (only used if backtrace logging is enabled). |
Middleware
Add query.logger middleware to your routes or groups if not using auto-registration:
Route::middleware(['query.logger'])->group(function () { Route::get('/', fn() => 'Hello World'); });
Manual Logging
Enable query logging anywhere:
QueryLogger::generateQueryLog($file_name);
Command Logging
Enable query logging inside an Artisan command:
QueryLogger::enableForCommand($this->getName());
Job Logging
Enable query logging inside a queued job:
QueryLogger::enableForJob(get_class($this));
Log Format
plain— human-readable logsjson— structured logs for programmatic analysis
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/MyFeature - Commit your changes:
git commit -m 'Add new feature' - Push to the branch:
git push origin feature/MyFeature - Submit a pull request
🔗 Repository Link: https://github.com/ataulgalib/query-debug
License
This package is open-sourced under the MIT license.
Author
Ataul Galib
Email: ataul.gonigalib@gmail.com
brrittoo/query-debug-tools 适用场景与选型建议
brrittoo/query-debug-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「database」 「performance」 「debugging」 「query」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 brrittoo/query-debug-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brrittoo/query-debug-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 brrittoo/query-debug-tools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Store your language lines in the database, yaml or other sources
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-02