加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 19:36:23 所属栏目:大数据 来源:网络整理
导读:我在laravel 5.3日志中有这个条目 2016-12-22 17:23:37] local.ERROR: GuzzleHttpExceptionClientException: Client error: POST https://api.sparkpost.com/api/v1/transmissions resulted in a 400 Bad Request response: { “errors”: [ { “message”
我在laravel 5.3日志中有这个条目

2016-12-22 17:23:37] local.ERROR:
GuzzleHttpExceptionClientException: 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(PsrLogLoggerInterface::class);
    } catch (Exception $ex) {
        throw $exception; // throw the original exception
    }

    // this is the new custom handling of guzzle exceptions
    if ($exception instanceof GuzzleHttpExceptionRequestException) {
        // 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方法中完成的,因此它只会影响写入日志的内容.如果将异常转储到终端或浏览器,它仍将显示截断的消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读