Skip to content

Commit 4a3a0cf

Browse files
authored
Merge pull request #74 from matthewtrask/master
allow for query logger to write to different logs
2 parents 99bd59d + eddeac6 commit 4a3a0cf

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

config/config.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* If this is set to "null", the app.debug config value will be used.
77
*/
88
'enabled' => env('QUERY_DETECTOR_ENABLED', null),
9-
9+
1010
/*
1111
* Threshold level for the N+1 query detection. If a relation query will be
1212
* executed more then this amount, the detector will notify you about it.
@@ -27,6 +27,13 @@
2727
//]
2828
],
2929

30+
/*
31+
* Here you can set a specific log channel to write to
32+
* in case you are trying to isolate queries or have a lot
33+
* going on in the laravel.log. Defaults to laravel.log though.
34+
*/
35+
'log_channel' => env('QUERY_DETECTOR_LOG_CHANNEL', 'daily'),
36+
3037
/*
3138
* Define the output format that you want to use. Multiple classes are supported.
3239
* Available options are:

src/Outputs/Log.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@ public function boot()
1515

1616
public function output(Collection $detectedQueries, Response $response)
1717
{
18-
LaravelLog::info('Detected N+1 Query');
18+
$this->log('Detected N+1 Query');
1919

2020
foreach ($detectedQueries as $detectedQuery) {
2121
$logOutput = 'Model: '.$detectedQuery['model'] . PHP_EOL;
22-
22+
2323
$logOutput .= 'Relation: '.$detectedQuery['relation'] . PHP_EOL;
2424

2525
$logOutput .= 'Num-Called: '.$detectedQuery['count'] . PHP_EOL;
26-
26+
2727
$logOutput .= 'Call-Stack:' . PHP_EOL;
2828

2929
foreach ($detectedQuery['sources'] as $source) {
3030
$logOutput .= '#'.$source->index.' '.$source->name.':'.$source->line . PHP_EOL;
3131
}
3232

33-
LaravelLog::info($logOutput);
33+
$this->log($logOutput);
3434
}
3535
}
36+
37+
private function log(string $message)
38+
{
39+
LaravelLog::channel(config('querydetector.log_channel'))->info($message);
40+
}
3641
}

0 commit comments

Comments
 (0)