https://github.com/mitoop/laravel-query-logger
There might be a problem if you don't see sql.
https://github.com/mitoop/laravel-query-logger
Last synced: 5 months ago
JSON representation
There might be a problem if you don't see sql.
- Host: GitHub
- URL: https://github.com/mitoop/laravel-query-logger
- Owner: mitoop
- Created: 2023-03-18T06:55:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-20T07:17:27.000Z (11 months ago)
- Last Synced: 2025-09-27T15:07:39.971Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Laravel Query Logger
🔮 轻松记录 SQL 执行日志,助力调试与分析
## 安装
```shell
composer require mitoop/laravel-query-logger
```
## 配置
在 config/logging.php 中添加日志频道配置:
```php
[
// 其他日志频道配置...
'sql' => [
'driver' => 'daily',
'path' => storage_path('logs/sql.log'),
'level' => env('LOG_LEVEL', 'debug'),
'permission' => 0664,
],
],
// 查询日志相关配置
'query' => [
'enabled' => env('ENABLE_QUERY_LOG', false), // 总开关,是否启用 SQL 查询日志
'channel' => 'sql', // 日志记录频道
'excluded_tables' => ['telescope_'], // 排除表名,支持前缀匹配
],
];
```
## 使用
#### 默认行为
当 `query.enabled` 设置为 `true` 时,包会自动记录所有的 SQL 查询日志,无需额外配置。
#### 自定义触发条件
如果你想根据自定义条件控制 SQL 日志的记录,可以在 `AppServiceProvider` 的 `boot()` 方法中,调用 `QueryDebugger::enableWhen()` 设置触发条件。
日志仅在 **总开关开启** 且 **自定义条件为真** 时,才会被记录。
```php
hasCookie('debug_sql');
});
}
```