php – 在laravel 5.3中截断的错误日志

前端之家收集整理的这篇文章主要介绍了php – 在laravel 5.3中截断的错误日志前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在laravel 5.3日志中有这个条目

2016-12-22 17:23:37] local.ERROR:
GuzzleHttp\Exception\ClientException: Client error: POST
https://api.sparkpost.com/api/v1/transmissions
resulted in a 400 Bad
Request
response: { “errors”: [ { “message”: “Message generation
rejected”,“description”: “recipient address suppressed due to
customer p (truncated…)

为什么它会截断一条重要的错误信息?现在我无法弄清楚出了什么问题……

解决方法

截断是由Guzzle库完成的.它仅显示响应的前120个字符.我假设这是因为回复可能会很长.

如果您想查看完整的消息,您应该能够自定义如何处理guzzle异常.

将app / Exceptions / Handler.PHP中的report()方法更新为:

public function report(Exception $exception)
{
    // this is from the parent method
    if ($this->shouldntReport($exception)) {
        return;
    }

    // this is from the parent method
    try {
        $logger = $this->container->make(\Psr\Log\LoggerInterface::class);
    } catch (Exception $ex) {
        throw $exception; // throw the original exception
    }

    // this is the new custom handling of guzzle exceptions
    if ($exception instanceof \GuzzleHttp\Exception\RequestException) {
        // get the full text of the exception (including stack trace),// and replace the original message (possibly truncated),// with the full text of the entire response body.
        $message = str_replace(
            rtrim($exception->getMessage()),(string) $exception->getResponse()->getBody(),(string) $exception
        );

        // log your new custom guzzle error message
        return $logger->error($message);
    }

    // make sure to still log non-guzzle exceptions
    $logger->error($exception);
}

注意:这是在report方法中完成的,因此它只会影响写入日志的内容.如果将异常转储到终端或浏览器,它仍将显示截断的消息.

猜你在找的Laravel相关文章