From 7dedc46dbfa83b2778c9b21c210c7a7c8bfc85b7 Mon Sep 17 00:00:00 2001 From: evotodi Date: Thu, 16 Sep 2021 17:58:39 -0400 Subject: [PATCH] Added options to reverse the logs form oldest at the top to newest. --- src/Controller/LogViewerController.php | 6 +++++- src/DependencyInjection/Configuration.php | 1 + .../EvotodiLogViewerExtension.php | 1 + src/Resources/config/evo_log_viewer.xml | 1 + src/Service/LogList.php | 12 ++++++++++-- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Controller/LogViewerController.php b/src/Controller/LogViewerController.php index 39cf4b1..0f77174 100644 --- a/src/Controller/LogViewerController.php +++ b/src/Controller/LogViewerController.php @@ -63,7 +63,11 @@ public function logViewAction(Request $request): Response } if(!empty($lines)){ - $context['log'] = $lines; + if($this->logList->getLogsReverse()) { + $context['log'] = array_reverse($lines); + }else { + $context['log'] = $lines; + } }else{ $context['noLog'] = true; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a7a9605..3ba6c3d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -46,6 +46,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->booleanNode('show_app_logs')->defaultTrue()->info('Show App logs in var/log')->end() ->scalarNode('app_pattern')->info('See ddtraceweb/monolog-parser for patterns.')->defaultNull()->end() ->scalarNode('app_date_format')->info('PHP style date format of app log files')->defaultNull()->end() + ->booleanNode('logs_reverse')->defaultFalse()->info('Show log file as newest at the top')->end() ->end(); return $treeBuilder; diff --git a/src/DependencyInjection/EvotodiLogViewerExtension.php b/src/DependencyInjection/EvotodiLogViewerExtension.php index 09da604..f09f0b2 100644 --- a/src/DependencyInjection/EvotodiLogViewerExtension.php +++ b/src/DependencyInjection/EvotodiLogViewerExtension.php @@ -27,6 +27,7 @@ public function load(array $configs, ContainerBuilder $container): array $definition->replaceArgument(2, $config['show_app_logs']); $definition->replaceArgument(3, $config['app_pattern']); $definition->replaceArgument(4, $config['app_date_format']); + $definition->replaceArgument(5, $config['logs_reverse']); return $config; } diff --git a/src/Resources/config/evo_log_viewer.xml b/src/Resources/config/evo_log_viewer.xml index 8a1d315..1b7084c 100644 --- a/src/Resources/config/evo_log_viewer.xml +++ b/src/Resources/config/evo_log_viewer.xml @@ -13,6 +13,7 @@ + diff --git a/src/Service/LogList.php b/src/Service/LogList.php index be9e482..8f9c0c2 100644 --- a/src/Service/LogList.php +++ b/src/Service/LogList.php @@ -5,7 +5,6 @@ use Evotodi\LogViewerBundle\Models\LogFile; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\Finder\Exception\DirectoryNotFoundException; use Symfony\Component\Finder\Finder; class LogList @@ -15,6 +14,7 @@ class LogList private bool $useAppLogs; private ?string $appPattern; private ?string $appDateFormat; + private ?bool $logsReverse; protected array $levels = [ "debug" => "DEBUG", @@ -26,13 +26,16 @@ class LogList "critical" => "CRITICAL", "emergency" => "EMERGENCY", ]; - public function __construct(ParameterBagInterface $parameterBag, array $logFiles, bool $useAppLogs = false, ?string $appPattern = null, ?string $appDateFormat = null) + + public function __construct(ParameterBagInterface $parameterBag, array $logFiles, bool $useAppLogs = false, ?string $appPattern = null, ?string $appDateFormat = null, ?bool $logsReverse = null) { $this->parameterBag = $parameterBag; $this->logFiles = $logFiles; $this->useAppLogs = $useAppLogs; $this->appPattern = $appPattern; $this->appDateFormat = $appDateFormat; + $this->logsReverse = $logsReverse; + if(is_null($this->appDateFormat)){ $this->appDateFormat = 'Y-m-d H:i:s'; } @@ -97,4 +100,9 @@ public function getLogList(): array } return $logs; } + + public function getLogsReverse(): ?bool + { + return $this->logsReverse; + } }