Skip to content

Commit 34c0f67

Browse files
committed
Update log format & env switch support. #4
1 parent 54a5263 commit 34c0f67

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ sftp-config.json
55
composer.lock
66
.subsplit
77
.php_cs.cache
8+
.idea/

src/ServiceProvider.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class ServiceProvider extends LaravelServiceProvider
2323
*/
2424
public function boot()
2525
{
26-
Log::info(sprintf('============ %s: %s ===============', request()->method(), request()->fullUrl()));
26+
if (isset($_SERVER['QUERY_LOGGER_ENABLED']) && !$_SERVER['QUERY_LOGGER_ENABLED']) {
27+
return;
28+
}
29+
2730
DB::listen(function (QueryExecuted $query) {
2831
$sqlWithPlaceholders = str_replace(['%', '?'], ['%%', '%s'], $query->sql);
2932

@@ -32,7 +35,7 @@ public function boot()
3235
$realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings));
3336
$duration = $this->formatDuration($query->time / 1000);
3437

35-
Log::debug(sprintf('[%s] %s', $duration, $realSql));
38+
Log::debug(sprintf('[%s] %s | %s: %s', $duration, $realSql, request()->method(), request()->getRequestUri()));
3639
});
3740
}
3841

@@ -53,11 +56,11 @@ public function register()
5356
private function formatDuration($seconds)
5457
{
5558
if ($seconds < 0.001) {
56-
return round($seconds * 1000000).'μs';
57-
} elseif ($seconds < 1) {
58-
return round($seconds * 1000, 2).'ms';
59+
return round($seconds * 1000000) . 'μs';
60+
} else if ($seconds < 1) {
61+
return round($seconds * 1000, 2) . 'ms';
5962
}
6063

61-
return round($seconds, 2).'s';
64+
return round($seconds, 2) . 's';
6265
}
6366
}

0 commit comments

Comments
 (0)