2017 © Pedro Peláez
 

library jkdumper

JKDumper is one-man-army quick'n'dirty debugging-logging tool

image

johnykvsky/jkdumper

JKDumper is one-man-army quick'n'dirty debugging-logging tool

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

JKDumper

Latest Version on Packagist ![Software License][ico-license] Total Downloads Build Status, (*1)

JKDumper is one-man-army quick'n'dirty debugging-logging tool. Good for both: - legacy applications, where you have spaghetti code - new projects, where you need to inject logger through 4 services just to dump some variables fot one time., (*2)

JKDumper is one file with optional logging library. Yes, it use singleton instance(), yes, it has static methods - it's just a tool and it need to be dead-simple to use in whatever sh**ty code we have to work., (*3)

Install

Via Composer, (*4)

``` bash $ composer require johnykvsky/jkdumper, (*5)


Should work fine on PHP 5.6, but I didn't check that. Just change required PHP version in composer.json and maybe remove dev packages. ## Features - Dumping variables to screen, basic formatting for easy reading - Detecting if run from CLI (for proper formatting) - Optional: logging variables to file (iw. when we want to check some process, not single thing) - Optional: simple benchmarking via microtime() If logger is set, then benchmarking is logged. Library use var_dump for dumping data, if needed it disable Xdebug 'overload_var_dump' (only for single dump, it is restored). ## Usage TL/DR: Nice way to make it a bit easier is to create function, ie. right after autoload:

require '../vendor/autoload.php';, (*6)

if (!function_exists('dde')) { function dde($var, $die = false) { \johnykvsky\Utils\JKDumper::instance()->vdump($var, true); if ($die) { die; } } }, (*7)


This will allow us to dump variable to screen like this, with optional stopping further execution (second parameter):

dde($myVariable); dde($myOtherVariable,1);, (*8)


Full example: ``` php //dump variables: $dumper = new \johnykvsky\Utils\JKDumper(); echo $dumper->vdump('test'); //or, better for dirty debugging: echo \johnykvsky\Utils\JKDumper::instance()->vdump('test'); //if you pass true as second parameter to vdump, result will be in


 tags (if in CLI, PHP_EOL will be added)
echo \johnykvsky\Utils\JKDumper::instance()->vdump('test', true);
//result: 

test
//benchmark start, parameter is optional \johnykvsky\Utils\JKDumper::instance()->startTime('usersQuery'); //info is also written into logs, if logger is set //do stomething, lets rest sleep(3); //stop and check results - we can run few benchmarks in the same time and get results by parameter name, //so passed parameter must be the same as we provided in startTime echo \johnykvsky\Utils\JKDumper::instance()->endTime('usersQuery'); //this is also written into logs, if logger is set //logging, somewhere in the code we need to create logger and pass it to JKDumper //usually it's good to do it somewhere at the beginning. index.php? base controller? //for JKLogger parameter is path where we want to store logs $logger = new \johnykvsky\Utils\JKLogger(__DIR__.'/files'); \johnykvsky\Utils\JKDumper::instance()->setLogger($logger); //and now we ca dump variables to logs anywhere, anytime \johnykvsky\Utils\JKDumper::instance()->log($request); //you can store results: $data['req'] = \johnykvsky\Utils\JKDumper::instance()->vdump($request); $data['res'] = \johnykvsky\Utils\JKDumper::instance()->vdump($response); //and log them later in one go: \johnykvsky\Utils\JKDumper::instance()->log($data);

Log file example:, (*9)

[2017-12-25 22:55:48.108006] [usersQuery] Started timing usersQuery
[2017-12-25 22:55:48.108288] [usersQuery] Finished debug in 0.279 milliseconds
[2017-12-25 22:55:48.124536] [debug] 'test'

It's good to look at log library to see how it works and how it can be customized: jklogger, (*10)

This is my choice of logger, but it can be replaced with anything compatibile with PSR-3 LoggerInterface, (*11)

Testing

``` bash $ composer test, (*12)


## Code checking ``` bash $ composer phpstan $ composer phpstan-max

Security

If you discover any security related issues, please email johnykvsky@protonmail.com instead of using the issue tracker., (*13)

Credits

License

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

The Versions

23/01 2018

dev-master

9999999-dev https://github.com/johnykvsky/JKDumper

JKDumper is one-man-army quick'n'dirty debugging-logging tool

  Sources   Download

MIT

The Requires

 

The Development Requires

dumper johnykvsky

11/01 2018

0.0.3

0.0.3.0 https://github.com/johnykvsky/JKDumper

JKDumper is one-man-army quick'n'dirty debugging-logging tool

  Sources   Download

MIT

The Requires

 

The Development Requires

dumper johnykvsky

06/01 2018

0.0.2

0.0.2.0 https://github.com/johnykvsky/JKDumper

dumper

  Sources   Download

MIT

The Requires

 

The Development Requires

dumper johnykvsky

27/12 2017

0.0.1

0.0.1.0 https://github.com/johnykvsky/JKDumper

dumper

  Sources   Download

MIT

The Requires

 

The Development Requires

dumper johnykvsky