@@ -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