Remove debug globals (#12811)

* Remove $debug global
and $vdebug global
makes these variables more accessible and protects from collisions.

* the on boot set sends application as the first parameter, just handle that

* Relocate other debug related functions

* Log debug to stdout

* Wrong output

* remove stupid constants

* Fix lint and style issues
This commit is contained in:
Tony Murray
2021-04-29 22:42:18 -05:00
committed by GitHub
parent 2cdd762656
commit 61c89794e4
51 changed files with 287 additions and 278 deletions

View File

@@ -24,10 +24,6 @@
namespace LibreNMS\Util;
use App;
use Illuminate\Database\Events\QueryExecuted;
use LibreNMS\DB\Eloquent;
use Log;
use Symfony\Component\HttpFoundation\HeaderBag;
class Laravel
@@ -77,56 +73,6 @@ class Laravel
return function_exists('app') && ! empty(app()->isAlias('Illuminate\Foundation\Application')) && app()->isBooted();
}
public static function enableQueryDebug()
{
static $sql_debug_enabled;
$db = Eloquent::DB();
if ($db && ! $sql_debug_enabled) {
$db->listen(function (QueryExecuted $query) {
// 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();
if (self::isBooted()) {
Log::debug("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n", ['color' => true]);
} else {
c_echo("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n");
}
});
$sql_debug_enabled = true;
}
}
public static function disableQueryDebug()
{
$db = Eloquent::DB();
if ($db) {
// remove all query executed event handlers
$db->getEventDispatcher()->flush('Illuminate\Database\Events\QueryExecuted');
}
}
public static function enableCliDebugOutput()
{
if (self::isBooted() && App::runningInConsole()) {
Log::setDefaultDriver('console');
}
}
public static function disableCliDebugOutput()
{
if (self::isBooted()) {
Log::setDefaultDriver('stack');
}
}
/**
* Add prefix and strip .php to make the url helper work in non-laravel php scripts
*