Debug Tools for Laravel
54
1
2
Package Data
Maintainer Username: Daniel Podsiadło
Package Create Date: 2016-06-21
Package Last Update: 2017-01-11
Language: PHP
License: MIT
Last Refreshed: 2024-12-29 15:10:36
Package Statistics
Total Downloads: 54
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

LDT - Debug Tools for Laravel

A package that extends Monolog and throws debug data to an external debugger.

Installation

Via Composer

$ composer require dpodsiadlo/ldt

Configuration

Once installed, register Laravel service provider, in your config/app.php:

'providers' => [
	...
    DPodsiadlo\LDT\Providers\LDTServiceProvider::class,
]

Also register a middleware for logging requests and responses, in your app/Http/Kernel.php:

protected $middleware = [
    ...
    \DPodsiadlo\LDT\Middleware\LogSender::class,        
];

You might also want to change the default (1800) port for external debugger (in .env):

LDT_DEBUG_PORT=1801

Basic Usage

Use default Laravel Log Facade that provides access to the 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);

Custom requests

Here is an example how to log a separate custom request with response, it might be helpful for debugging third party APIs:

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

Custom storage

Also it's possible to store the custom log to a separate log file:

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

Log file name will be generated automatically based on $storage parameter and Laravel app.log config. By default log will be generated in single mode.

Remote debugging

You might also want to debug a remote instance of your project. To do that please use SSH client with port forwarding enabled:

ssh me@some-server.com -R 1800:localhost:1800

External Debugger

LDT is compatible with LDT Console - Free Chrome App.

License

The MIT License (MIT). Please see License File for more information.