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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to get level color
|
||||
*
|
||||
* @param $level
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function levelColor($level)
|
||||
{
|
||||
$colors = [
|
||||
@@ -121,10 +127,21 @@ class LogViewer
|
||||
'logger' => $data['logger'],
|
||||
'level' => $data['level'],
|
||||
'message' => $data['message'],
|
||||
'trace' => $data['trace'] ?? null,
|
||||
'trace' => isset($data['trace']) ? $this->parseTrace($data['trace']) : null,
|
||||
'context' => json_decode($data['context'], 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) {
|
||||
$output = "<yellow>{$log['date']->format('Y-m-d h:i:s')}</yellow> [<{$level_color}>{$log['level']}</{$level_color}>]";
|
||||
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 {
|
||||
$output .= " {$log['message']}";
|
||||
}
|
||||
$io->writeln($output);
|
||||
if ($verbose) {
|
||||
$io->newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user