Skip to content

Commit 3018700

Browse files
committed
fix: logger handler
1 parent 0c16790 commit 3018700

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/QueryLoggerServiceProvider.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
class QueryLoggerServiceProvider extends ServiceProvider
1313
{
14+
public const MYSQL = 'mysql';
15+
public const SQLITE = 'sqlite';
16+
public const MONGODB = 'mongodb';
17+
1418
/**
1519
* Bootstrap services.
1620
*
@@ -38,19 +42,16 @@ public function boot(Request $request)
3842
*/
3943
protected function listenQueryLogging(LogManager $logger)
4044
{
41-
// Enable query logging for all connection
42-
foreach (array_keys(config('database.connections')) as $connection) {
43-
app('db')->connection($connection)->enableQueryLog();
44-
}
45+
app('db')->connection()->enableQueryLog();
4546

4647
app('db')->listen(function (QueryExecuted $query) use ($logger) {
4748
$driver = $query->connection->getDriverName();
4849

49-
if (in_array($driver, ['mysql', 'sqlite'])) {
50+
if (in_array($driver, [static::SQLITE, static::MYSQL])) {
5051
$this->writeMySqlLog($query, $logger);
5152
}
5253

53-
if ($driver === 'mongodb') {
54+
if ($driver === static::MONGODB) {
5455
$this->writeMongoDbLog($query, $logger);
5556
}
5657
});

0 commit comments

Comments
 (0)