feyman / laravel-sql-logger
一个用于记录laravel/lumen应用程序所有查询的工具。
0.0.5
2018-02-02 13:45 UTC
Requires
- illuminate/support: 5.0.* || 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*
This package is not auto-updated.
Last update: 2024-09-29 05:49:18 UTC
README
📝 此包允许您将SQL查询(包括慢查询)记录到Laravel/Lumen框架的日志文件中。灵感来源于 mnabialek/laravel-sql-logger
安装
composer require feyman/laravel-sql-logger --dev
请保留 --dev 选项。(建议只在开发中使用此包)。当 APP_DEBUG 为 true 时,日志将启用
配置
如果您使用Laravel < 5.5,请打开 app/Providers/AppServiceProvider.php 并在 register 方法中添加
public function register() { if ($this->app['config']->get('app.debug')) { $this->app->register(\Feyman\LaravelSqlLogger\Providers\ServiceProvider::class); } }
Laravel 5.5 使用包自动发现,它会自动加载此服务提供者,因此您不需要在上面的文件中添加任何内容。
如果您使用Lumen,请打开 bootstrap/app.php 并添加
if (env('APP_DEBUG')) { $app->register(\Feyman\LaravelSqlLogger\Providers\LumenServiceProvider::class); }
如果您使用Laravel < 5.5,请在控制台中运行
php artisan vendor:publish --provider="Feyman\LaravelSqlLogger\Providers\ServiceProvider"
以发布默认配置文件。
如果您使用Laravel 5.5,请运行
php artisan vendor:publish
并选择匹配 "Feyman\LaravelSqlLogger\Providers\ServiceProvider" 提供者的数字。此操作将在 config/sql_loger.php 中创建配置文件。默认情况下,您不应该编辑已发布的文件,因为所有设置都是默认从 .env 文件加载的。
对于Lumen,您应跳过此步骤。
在您的 .env 文件中添加以下条目
# Whether all SQL queries should be logged
SQL_LOG_QUERIES=true
# Whether slow SQL queries should be logged (you can log all queries and
# also slow queries in separate file or you might to want log only slow queries)
SQL_LOG_SLOW_QUERIES=true
# Time of query (in milliseconds) when this query is considered as slow
SQL_SLOW_QUERIES_MIN_EXEC_TIME=100
#Whether slow SQL queries should be logged (you can log all queries and
#also slow queries in separate file or you might to want log only slow queries)
SQL_LOG_OVERRIDE=false
# Directory where log files will be saved
SQL_LOG_DIRECTORY=logs/sql
# Whether execution time in log file should be displayed in seconds(by default it's in milliseconds)
SQL_CONVERT_TIME_TO_SECONDS=false
# Whether artisan queries should be logged to separate files
SQL_LOG_SEPARATE_ARTISAN=false
许可证
MIT