Logging each Request

@return \Closure
763152
public function log() : \Closure
    {
        $logger    = $this->logger;
        $formatter = $this->formatter;

        return function (callable $handler) use ($logger, $formatter) {

            return function ($request, array $options) use ($handler, $logger, $formatter) {
                // generate id that will be used to supplement the log with information
                $requestId = uniqid('eight_points_guzzle_');

                // initial registration of log
                $logger->info('', compact('request', 'requestId'));

                // this id will be used by RequestTimeMiddleware
                $options['request_id'] = $requestId;

                return $handler($request, $options)->then(

                    function ($response) use ($logger, $request, $formatter, $requestId) {

                        $message = $formatter->format($request, $response);
                        $context = compact('request', 'response', 'requestId');

                        $logger->info($message, $context);

                        return $response;
                    },

                    function ($reason) use ($logger, $request, $formatter, $requestId) {

                        $response = $reason instanceof RequestException ? $reason->getResponse() : null;
                        $message  = $formatter->format($request, $response, $reason);
                        $context  = compact('request', 'response', 'requestId');

                        $logger->notice($message, $context);

                        return \GuzzleHttp\Promise\rejection_for($reason);
                    }
                );
            };
        };
    }
768139
public function onRequestDetails()
    {
        Breadcrumbs::register('logger-request', function($breadcrumbs) {
            $breadcrumbs->push('Request Log', handles('antares::logger/request/index'), ['force_link' => true]);
        });
        $date = Request::route()->parameter('date');
        Breadcrumbs::register('logger-request-' . $date, function($breadcrumbs) use($date) {
            $breadcrumbs->parent('logger-request');
        });
        view()->share('breadcrumbs', Breadcrumbs::render('logger-request-' . $date));
    }
482879
public function handle($request, Closure $next)
    {
        if (auth()->guest() || !user()->hasRoles(['client', 'member'])) {
            return $next($request);
        }
        $this->beforeSendingThroughPipeline();
        $response = $next($request);
        $this->afterSendingThroughPipeline();

        return $response;
    }
797435
public static function captureQueries(\Closure $closure)
    {
        DB::enableQueryLog();
        $closure();
        $logs = DB::getQueryLog();
        return array_map(function ($log) {
            return static::inlineBindings($log['query'], $log['bindings']);
        }, $logs);
    }
947111
public function log(): void
    {
        $this->logger->log($this->message(), LOG_ERR, $this->tuple);
    }
652550
protected function carry(): Closure
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                if ($this->always !== null) {
                    $passable = ($this->always)($passable, $pipe);
                }
                $slice = parent::carry();

                $callable = $slice($stack, $pipe);

                return $callable($passable);
            };
        };
    }
1327646
public function toLogString()
    {
        $logParts = array();
        if ($this->getStatus() !== null) {
            $logParts[] = 'status=' . $this->getStatus();
        }
        if ($this->getRawRequest() !== null) {
            $logParts[] = 'request=' . $this->getRawRequest();
        }
        if ($this->getRawResponse() !== null) {
            $logParts[] = 'response=' . $this->getRawResponse();
        }
        if ($this->getException() !== null) {
            $logParts[] = $this->getException()->__toString();
        }
        return implode('; ', $logParts);
    }
950
protected function dispatchToRouter() : Closure
    {
        return function ($request) {
            return $this->router->setContainer($this->container)->dispatch($request);
        };
    }
484935
protected function logRouteCompletion()
    {
        $executionTime = microtime(true) - $this->executionStart;

        $logger = Strata::app()->getLogger();
        if ($logger) {
            $logger->logContextEnd(sprintf("Done in %s seconds", round($executionTime, 4)), "<green>Route</green>");
        }
    }
829706
protected function _process()
    {
        if (is_callable($this->_handler)) {
            return $this->_processDelegated();
        }
        $spec = $this->_actual;

        if (!$spec instanceof Specification || $spec->passed() !== null) {
            return $this;
        }

        $closure = function () use ($spec) {
            $spec->reset();
            $spec->process($result);
            $this->_logs = $spec->logs();
            return $this->_passed = $spec->passed();
        };

        try {
            $this->_spin($closure);
        } catch (TimeoutException $e) {
        }
        if ($exception = $spec->log()->exception()) {
            throw $exception;
        }

        $this->_passed = $spec->passed() && ($this->_passed === null ? true : $this->_passed);
        return $this;
    }
1172546
function logRoute(routeConfig, filters) {
        filters = filters ? filters.join(', ') : "";
        $log.info(
            '{method="%s", path="%s", filters="%s"} bind on controller %s#%s',
            routeConfig.method,
            routeConfig.path,
            filters,
            routeConfig.controller,
            routeConfig.action
        );
    }
325525
protected function makeCallable()
    {
        if ($this->call instanceof Closure || $this->isFunction()) {
            return $this->call;
        }

        if ($this->isStaticMethod()) {
            return [$this->getCallClass(), $this->getCallMethod()];
        }

        return [$this->getCallInstance(), $this->getCallMethod()];

    }
265208
public function PHPShutdownHandler()
    {
        session_write_close();
        if ($lasterror = error_get_last()) {
            $message = $lasterror['message'] . ' | File: {file} | Ln: {line}';
            $context = array(
                'file' => $lasterror['file'],
                'line' => $lasterror['line']
            );
            $this->logger->log($this->shutdownLogLevel, $message, $context);
        }
    }
650487
protected function invokeLogging() {
        $this->config['log'] = [
            'colorize' => true,
            'verbosity' => Log::ALL | ~Log::DEBUG
        ];

        $this->log = new Log();

        return $this;
    }
301918
public function cliRegister() : Closure
  {
    return function($exception, $inspector, $run) {
      Output::error($exception);
      die($exception . PHP_EOL);
      exit;
    };
  }
450368
private function submitting(Closure $then = null) : void
    {
        $this->spouting(co(function (array $spans) use ($then) {
            $request = new Request(
                'POST',
                new Uri('http', $this->endpoint->host(), $this->endpoint->port(), self::API),
                [
                    'Content-Type' => 'application/json',
                ],
                new Body(sprintf('[%s]', implode(',', $spans)))
            );
            try {
                /**
                 * @var Response $response
                 */
                $response = yield $this->client->perform($request);
                if ($response->getStatusCode() !== 202) {
                    logger('traced')->notice(
                        'Server not accepting',
                        [
                            'endpoint' => (string)$request->getUri(),
                            'error' => sprintf('#%d->%s', $response->getStatusCode(), (string)$response->getBody()),
                            'payload' => debug() ? (string)$request->getBody() : '[IGNORED]',
                        ]
                    );
                }
            } catch (RequestException | SelectWaitException $e) {
                logger('traced')->notice(
                    'Posting failed',
                    [
                        'endpoint' => (string)$request->getUri(),
                        'error' => sprintf('%s::%s', get_class($e), $e->getMessage()),
                    ]
                );
            }
            $then && $then();
        }));
    }
758017
public function getLogs(){
        $rest = $this->getService( self::API_VPN_CLIENT_LOGS);
        $rest->GET();

        return $rest->getResult();
    }