mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user