From 07ea6d0c4745c17129784a00324f6a0db8c00907 Mon Sep 17 00:00:00 2001 From: Martin Kluska Date: Thu, 4 May 2023 13:30:39 +0200 Subject: [PATCH] feat(Log): Add extra line for line/debug --- src/Log/Handlers/ConsoleOutputHandler.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Log/Handlers/ConsoleOutputHandler.php b/src/Log/Handlers/ConsoleOutputHandler.php index 829aeba0..09ba8622 100644 --- a/src/Log/Handlers/ConsoleOutputHandler.php +++ b/src/Log/Handlers/ConsoleOutputHandler.php @@ -9,6 +9,7 @@ use LaraStrict\Log\Managers\ConsoleOutputManager; use Monolog\Handler\AbstractProcessingHandler; use Monolog\Logger; +use Symfony\Component\Console\Output\OutputInterface; /** * @internal @@ -32,6 +33,8 @@ protected function write(array $record): void return; } + $context = $record['context']; + $hasContext = $context !== []; $message = $record['message']; switch ($record['level']) { @@ -51,15 +54,11 @@ protected function write(array $record): void $consoleOutputFactory->error($message); break; default: - $outputStyle->newLine(); - $outputStyle->write(messages: ' ' . $message . ''); - $outputStyle->newLine(); + $this->writeLine(outputStyle: $outputStyle, message: $message, hasContext: $hasContext); break; } - $context = $record['context']; - - if ($context !== []) { + if ($hasContext) { foreach ($context as $line => $value) { $isGenericValue = is_string($value) || is_int($value) || is_float($value) || is_bool($value); @@ -77,4 +76,15 @@ protected function write(array $record): void $outputStyle->newLine(); } } + + protected function writeLine(OutputStyle $outputStyle, mixed $message, bool $hasContext): void + { + $outputStyle->newLine(); + $outputStyle->write(messages: ' ' . $message . ''); + $outputStyle->newLine(); + + if ($hasContext === false) { + $outputStyle->newLine(); + } + } }