Skip to content

Commit

Permalink
Merge pull request #40 from guanguans/master
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Sep 26, 2024
2 parents b9fb545 + aca0ed8 commit 5fdcbf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ return [

// Only record queries that are slower than the following time
// Unit: milliseconds
'slower_than' => 0,
'slower_than' => 0,

// Only record queries when the QUERY_LOG_TRIGGER is set in the environment,
// or when the trigger HEADER, GET, POST, or COOKIE variable is set.
'trigger' => env('QUERY_LOG_TRIGGER'),
'trigger' => env('QUERY_LOG_TRIGGER'),

// Except record queries
'except' => [
// '*_telescope_*',
],

// Log Channel
'channel' => 'stack',
Expand Down
7 changes: 5 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public function boot()
}

$this->app['events']->listen(QueryExecuted::class, function (QueryExecuted $query) {
if ($query->time < $this->app['config']->get('logging.query.slower_than', 0)) {
if (
$query->time < $this->app['config']->get('logging.query.slower_than', 0)
|| str($query->sql)->is($this->app['config']->get('logging.query.except', []))
) {
return;
}

Expand All @@ -46,7 +49,7 @@ public function boot()

if (count($bindings) > 0) {
$realSql = vsprintf($sqlWithPlaceholders, array_map(
static fn($binding) => $binding === null ? 'NULL' : $pdo->quote($binding),
static fn ($binding) => $binding === null ? 'NULL' : $pdo->quote($binding),
$bindings
));
}
Expand Down

0 comments on commit 5fdcbf0

Please sign in to comment.