Enhancements to logviewer output to support lines in trace

This commit is contained in:
Andy Miller
2019-01-31 18:38:31 -07:00
parent a3fea3d0fc
commit e4b1d2ed9e
2 changed files with 22 additions and 5 deletions

View File

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

View File

@@ -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 {