librenms/app/Listeners/QueryDebugListener.php
Tony Murray 014213680f
Move Config loading to a service provider (#13927)
* Move Config loading to a service provider
That way other service providers can depend on it
Move various random listener registrations into the EventServiceProvider
Various startup cleanup

* Config::persist Set live variable before persisting incase db update fail

* Disable strict mode for legacy code (init.php)

* Disable debug after os test data is gathered

* remove Eloquent::boot it is never used

* remove Eloquent::version

* lint fixes

* style fixes

* there is no c_echo here
2022-04-22 19:12:07 -05:00

44 lines
956 B
PHP

<?php
namespace App\Listeners;
use Illuminate\Database\Events\QueryExecuted;
use LibreNMS\Util\Debug;
use Log;
class QueryDebugListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \Illuminate\Database\Events\QueryExecuted $query
* @return void
*/
public function handle(QueryExecuted $query)
{
if (Debug::queryDebugIsEnabled()) {
// collect bindings and make them a little more readable
$bindings = collect($query->bindings)->map(function ($item) {
if ($item instanceof \Carbon\Carbon) {
return $item->toDateTimeString();
}
return $item;
})->toJson();
Log::debug("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n", ['color' => true]);
}
}
}