mirror of
https://github.com/getgrav/grav.git
synced 2025-12-05 15:29:57 +01:00
Enhancements to logviewer output to support lines in trace
This commit is contained in:
@@ -79,6 +79,12 @@ class LogViewer
|
|||||||
return trim($output);
|
return trim($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to get level color
|
||||||
|
*
|
||||||
|
* @param $level
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
public static function levelColor($level)
|
public static function levelColor($level)
|
||||||
{
|
{
|
||||||
$colors = [
|
$colors = [
|
||||||
@@ -121,10 +127,21 @@ class LogViewer
|
|||||||
'logger' => $data['logger'],
|
'logger' => $data['logger'],
|
||||||
'level' => $data['level'],
|
'level' => $data['level'],
|
||||||
'message' => $data['message'],
|
'message' => $data['message'],
|
||||||
'trace' => $data['trace'] ?? null,
|
'trace' => isset($data['trace']) ? $this->parseTrace($data['trace']) : null,
|
||||||
'context' => json_decode($data['context'], true),
|
'context' => json_decode($data['context'], true),
|
||||||
'extra' => json_decode($data['extra'], true)
|
'extra' => json_decode($data['extra'], true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text of trace into an array of lines
|
||||||
|
*
|
||||||
|
* @param $trace
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function parseTrace($trace)
|
||||||
|
{
|
||||||
|
return array_filter(preg_split('/#\d*/m', $trace));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,14 +71,14 @@ class LogViewerCommand extends ConsoleCommand
|
|||||||
if ($date instanceof \DateTime) {
|
if ($date instanceof \DateTime) {
|
||||||
$output = "<yellow>{$log['date']->format('Y-m-d h:i:s')}</yellow> [<{$level_color}>{$log['level']}</{$level_color}>]";
|
$output = "<yellow>{$log['date']->format('Y-m-d h:i:s')}</yellow> [<{$level_color}>{$log['level']}</{$level_color}>]";
|
||||||
if ($log['trace'] && $verbose) {
|
if ($log['trace'] && $verbose) {
|
||||||
$output .= " <white>{$log['message']}</white> - {$log['trace']}";
|
$output .= " <white>{$log['message']}</white>\n";
|
||||||
|
foreach ((array) $log['trace'] as $index => $tracerow) {
|
||||||
|
$output .= "<white>{$index}</white>${tracerow}\n";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$output .= " {$log['message']}";
|
$output .= " {$log['message']}";
|
||||||
}
|
}
|
||||||
$io->writeln($output);
|
$io->writeln($output);
|
||||||
if ($verbose) {
|
|
||||||
$io->newLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user