Skip to content

Commit

Permalink
Added options to reverse the logs form oldest at the top to newest.
Browse files Browse the repository at this point in the history
  • Loading branch information
evotodi committed Sep 16, 2021
1 parent 724dead commit 7dedc46
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Controller/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/EvotodiLogViewerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/evo_log_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<argument/>
<argument/>
<argument/>
<argument/>
</service>
<service id="Evotodi\LogViewerBundle\Service\LogList" alias="evotodi_log_list.log_list_service"/>

Expand Down
12 changes: 10 additions & 2 deletions src/Service/LogList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +14,7 @@ class LogList
private bool $useAppLogs;
private ?string $appPattern;
private ?string $appDateFormat;
private ?bool $logsReverse;

protected array $levels = [
"debug" => "DEBUG",
Expand All @@ -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';
}
Expand Down Expand Up @@ -97,4 +100,9 @@ public function getLogList(): array
}
return $logs;
}

public function getLogsReverse(): ?bool
{
return $this->logsReverse;
}
}

0 comments on commit 7dedc46

Please sign in to comment.