Created
October 26, 2019 15:37
-
-
Save phroggyy/38877e4dc6739a01b4433e7a9c32cfeb to your computer and use it in GitHub Desktop.
Revisions
-
phroggyy created this gist
Oct 26, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ <?php namespace App\Jobs; use Decahedron\StickyLogging\StickyContext; use Exception; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Http\Kernel; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; class LogStackVariables implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * @var string */ private $tempFileName; /** * @var Request */ private $capturedRequest; /** * @var null */ private $requestId; /** * Create a new job instance. * * @param string $tempFileName * @param Exception $exception * @param Request $capturedRequest */ public function __construct(string $tempFileName, Request $capturedRequest, $requestId = null) { $this->tempFileName = $tempFileName; $this->capturedRequest = $capturedRequest; $this->requestId = $requestId; } /** * Execute the job. * * @return void */ public function handle(Kernel $kernel) { if ($this->requestId) { StickyContext::add('request', $this->requestId); } require_once $this->tempFileName; $this->capturedRequest['__debug_mode__'] = true; $kernel->handle($this->capturedRequest); unlink($this->tempFileName); Log::debug('ran debug request', ['vars' => StickyContext::stack('vars')->all()]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ $request = $this->container['request']; if ($this->container->runningInConsole() || $request['__debug_mode__']) { return; } $lines = file($exception->getFile()); $prepend = "\\Decahedron\\StickyLogging\\StickyContext::stack('vars')->add('{$exception->getFile()}:{$exception->getLine()}', get_defined_vars());"; $lines[$exception->getLine()-1] = $prepend . $lines[$exception->getLine()-1]; $newFile = substr($exception->getFile(), 0, -4) . Str::random() . '.php'; file_put_contents($newFile, implode("", $lines)); dispatch(new LogStackVariables($newFile, Request::capture()));