dongyan1974 2016-12-22 23:18
浏览 162
已采纳

在laravel 5.3中截断的错误日志

i have this entry in my laravel 5.3 log

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...)

why does it truncate an important error message? now i cannot figure out what is going wrong...

  • 写回答

3条回答 默认 最新

  • dongshou9343 2016-12-23 01:17
    关注

    The truncating is done by the Guzzle library. It only shows the first 120 characters of the response. I am assuming this is because responses could potentially be very long.

    If you would like to see the full message, you should be able to customize how guzzle exceptions are handled.

    Update the report() method in your app/Exceptions/Handler.php to something like:

    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);
    }
    

    Note: this is done in the report method, so it only affects what is written to the log. If the exception is dumped to the terminal or to the browser, it will still show the truncated message.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)