<?php

namespace Dipper\Foundation\Debugger\Queries;

use Illuminate\Support\Facades\DB;

class QueryDebuggerJob
{
    /**
     * DB查询日志
     *
     * @return void
     */
    public function handle()
    {
        $debuggerEnabled = config('dipper.debugger.queries.debug');

        if ($debuggerEnabled) {
            DB::listen(function ($event) {
                $output = new Output($event);
                $output->newQuery();
                $output->spaceLine();
                $output->sql();
                $output->spaceLine();
                (new QueriesLogger())->releaseOutput($output);
            });
        }
    }
}
