Skip to content

Commit a2d096f

Browse files
committed
Add config support. #15
1 parent 841d6ee commit a2d096f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ $ tail -f ./storage/logs/laravel.log
2323
[2017-09-05 14:52:14] local.DEBUG: [3.63s] select `tags`.*, `taggables`.`taggable_id` as `pivot_taggable_id`, `taggables`.`tag_id` as `pivot_tag_id` from `tags` inner join `taggables` on `tags`.`id` = `taggables`.`tag_id` where `taggables`.`taggable_id` in ('1', '2', '3', '4', '5', '6', '7', '8') and `taggables`.`taggable_type` = 'App\\Models\\Discussion' order by `order_column` asc | GET: http://laravel.app/discussions
2424
[2017-09-05 14:52:14] local.DEBUG: [670μs] select * from `users` where `users`.`id` in ('1', '2', '4') and `users`.`deleted_at` is null | GET: http://laravel.app/discussions
2525
...
26+
27+
### Configuration
28+
29+
If you want to use it in a production environment, you can control whether or not to log a query via the configuration file:
30+
31+
*config/logging.php:*
32+
33+
```php
34+
return [
35+
//...
36+
'query' => [
37+
'enabled' => env('LOG_QUERY', false),
38+
39+
// Only record queries that are slower than the following time
40+
// Unit: milliseconds
41+
'slower_than' => 0,
42+
],
43+
];
44+
```
45+
2646

2747
## PHP 扩展包开发
2848

src/ServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ class ServiceProvider extends LaravelServiceProvider
2323
*/
2424
public function boot()
2525
{
26-
if (!$this->app['config']->get('app.debug')) {
26+
if (!$this->app['config']->get('app.debug') && !$this->app['config']->get('logging.query.enabled', false)) {
2727
return;
2828
}
2929

3030
DB::listen(function (QueryExecuted $query) {
31+
if ($query->time < $this->app['config']->get('logging.query.slower_than', 0)) {
32+
return;
33+
}
34+
3135
$sqlWithPlaceholders = str_replace(['%', '?'], ['%%', '%s'], $query->sql);
3236

3337
$bindings = $query->connection->prepareBindings($query->bindings);

0 commit comments

Comments
 (0)