Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

[[file:README_cn.org][中文说明]]
* Dependency
- laravel 5 (5.0 - 5.5)
- laravel 5-10 (for version 5 and higher laravel 10)
- [[https://github.com/barryvdh/laravel-debugbar][barryvdh/laravel-debugbar]] (laravel-debugbar itself dosen't display debug messages in console)
* Introduction

=composer require biohazard/laravel-console-debug=

This package can show laravel-debugbar's debug messages and SQL queries in *console*.

For example, there have a =test= command
Expand Down Expand Up @@ -41,6 +44,14 @@ For example, there have a =test= command
+-------------------------------+----------+
| select * from `users` limit 1 | 9.77ms |
+-------------------------------+----------+

+-------------+---------+
| Name | Memory |
+-------------+---------+
| Booting | 17.47MB |
| Application | 8.77MB |
+-------------+---------+

#+END_SRC

=Test= command's example (this example require laravel 5.4+ to run, you need put these code in =routes/console.php=, for laravel 5.3 and below you can use =Command= class)
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "frostrain/laravel-console-debug",
"name": "biohazard/laravel-console-debug",
"description": "Show debug informations in console",
"keywords": ["laravel", "debug"],
"type": "library",
Expand All @@ -11,7 +11,8 @@
}
],
"require": {
"barryvdh/laravel-debugbar": "2.*|3.*"
"barryvdh/laravel-debugbar": "2.*|3.*",
"biohazard/laravel-debugbar-memory": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 28 additions & 3 deletions src/ConsoleOutputDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\TableSeparator;
use Illuminate\Support\Arr;

class ConsoleOutputDebugCommand extends Command
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public function handle()
if (!$this->output->isVerbose()) {
return;
}
$this->debugbar = $this->laravel->make('debugbar');
$this->debugbar = app()->make('debugbar');
$this->columnLengthLimit = config('console_debug.column_length_limit');
$this->debugMessageStyles = config('console_debug.debug_message_styles');

Expand All @@ -70,6 +71,30 @@ public function handle()

$this->outputMessages();
$this->outputSqls();
$this->outputMemory();
}

protected function outputMemory()
{

if (!$this->debugbar->hasCollector('memory_details')) {
return;
}

$memories = $this->debugbar
->getCollector('memory_details')
->collect();

$memories = $memories['measures'];

$memories = Arr::map($memories, function (string $value, string $key) {
return [$key, $value];
});

$this->table(
['Name', 'Memory'],
$memories
);
}

protected function outputMessages()
Expand Down Expand Up @@ -102,7 +127,7 @@ protected function outputMessages()
$this->info('');
// table 方法传入的 $header 和 $data 最好是 元素数目相等, 并且顺序对应...
// 否则结果会比较怪异
$header = ['level', 'debug message'];
$header = ['Level', 'Debug message'];
// table 方法无法设置 verbosity ...
$this->table($header, $rows);
}
Expand Down Expand Up @@ -158,7 +183,7 @@ protected function outputSqls()
$this->line('');
// table 方法传入的 $header 和 $data 最好是 元素数目相等, 并且顺序对应...
// 否则结果会比较怪异
$header = ['sql', 'duration'];
$header = ['SQL', 'Duration'];
// table 方法无法设置 verbosity ...
$this->table($header, $rows);
}
Expand Down