dpodsiadlo / ldt
Laravel调试工具
v1.1.1
2017-01-09 09:38 UTC
Requires
- php: >=5.6
- illuminate/database: >=5.2
- illuminate/http: >=5.2
- illuminate/support: >=5.2
- monolog/monolog: >=1.19
- symfony/http-foundation: >=3.0
This package is not auto-updated.
Last update: 2024-09-23 14:24:02 UTC
README
一个扩展Monolog并将调试数据输出到外部调试器的包。
安装
通过Composer
$ composer require dpodsiadlo/ldt
配置
安装后,在您的config/app.php
中注册Laravel服务提供者。
'providers' => [ ... DPodsiadlo\LDT\Providers\LDTServiceProvider::class, ]
同时,在您的app/Http/Kernel.php
中注册一个用于记录请求和响应的中件件。
protected $middleware = [ ... \DPodsiadlo\LDT\Middleware\LogSender::class, ];
您可能还想更改外部调试器的默认端口(在.env
中为1800)。
LDT_DEBUG_PORT=1801
基本用法
使用默认的Laravel Log Facade,该 facade 提供对 Monolog Writter 的访问。
use Log; //Laravel Log Facade ... Log::emergency($error); Log::alert($error); Log::critical($error); Log::error($error); Log::warning($error); Log::notice($error); Log::info($error); Log::debug($error);
自定义请求
以下是一个如何记录带有响应的单独自定义请求的示例,这可能对调试第三方API有所帮助。
use DPodsiadlo\LDT\LDT; use DPodsiadlo\LDT\Log\Request; use DPodsiadlo\LDT\Log\Response; ... $params = ["param1" => "someValue"]; $targetUrl = "https://third-party-service.com"; $context = stream_context_create([ 'http' => [ 'header' => "Accept: */*\r\nContent-Type: application/json\r\nUser-Agent: API-WRAPER/1.0\r\n", 'method' => "POST", 'content' => json_encode($params), 'ignore_errors' => true ] ]); $res = file_get_contents($targetUrl, false, $context); if (!empty($http_response_header)) { $status = (int)explode(' ', $http_response_header[0])[1]; LDT::log(new Request($targetUrl, "POST", $params), new Response($res, $status, $http_response_header]), true); }
自定义存储
还可以将自定义日志存储到单独的日志文件中。
use DPodsiadlo\LDT\LDT; use DPodsiadlo\LDT\Log\Request; use DPodsiadlo\LDT\Log\Response; ... $params = ["param1" => "someValue"]; $targetUrl = "https://third-party-service.com"; $context = stream_context_create([ 'http' => [ 'header' => "Accept: */*\r\nContent-Type: application/json\r\nUser-Agent: API-WRAPER/1.0\r\n", 'method' => "POST", 'content' => json_encode($params), 'ignore_errors' => true ] ]); $res = file_get_contents($targetUrl, false, $context); if (!empty($http_response_header)) { $status = (int)explode(' ', $http_response_header[0])[1]; LDT::log(new Request($targetUrl, "POST", $params), new Response($res, $status, $http_response_header]), true, "third-party-log"); }
日志文件名将根据$storage
参数和Laravel的app.log
配置自动生成。默认情况下,日志将在single
模式下生成。
远程调试
您可能还想调试您的项目的远程实例。为此,请使用具有端口转发的SSH客户端。
ssh me@some-server.com -R 1800:localhost:1800
外部调试器
LDT与LDT Console - 免费Chrome应用兼容。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。