diff --git a/README.md b/README.md index 55baa7d3..e5ab008e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Default configuration: [(Configuration reference)](https://github.com/frankdekke ```yaml fd_log_viewer: home_route: null + show_performance_details: true log_files: monolog: diff --git a/docs/configuration-reference.md b/docs/configuration-reference.md index c4d1b39c..46a64b4f 100644 --- a/docs/configuration-reference.md +++ b/docs/configuration-reference.md @@ -7,6 +7,7 @@ Out of the box, [Log viewer](../README.md) will have the following configuration ```yaml fd_log_viewer: home_route: null + show_performance_details: true log_files: monolog: @@ -39,6 +40,12 @@ fd_log_viewer: The name of the route that will be used as url for the back button. If null the back button will redirect to `https://your-domain/`.

+### show_performance_details +type: `boolean`. Default: `true` + +Show the performance details (memory, duration and package version) in the footer or not. +

+ ### log_files **type**: `array` diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7ac81281..d0412184 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -26,6 +26,10 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() ->scalarNode('home_route')->info("The name of the route to redirect to when clicking the back button")->end() + ->scalarNode('show_performance_details') + ->defaultTrue() + ->info("Will toggle if the performance information and version will be shown. Default true") + ->end() ->append($this->configureLogFiles()) ->append($this->configureHosts()); diff --git a/src/DependencyInjection/Extension.php b/src/DependencyInjection/Extension.php index 98d96c0c..9c60cd49 100644 --- a/src/DependencyInjection/Extension.php +++ b/src/DependencyInjection/Extension.php @@ -7,6 +7,7 @@ use FD\LogViewer\Entity\Config\HostAuthenticationConfig; use FD\LogViewer\Entity\Config\HostConfig; use FD\LogViewer\Entity\Config\LogFilesConfig; +use FD\LogViewer\Service\File\LogRecordsOutputProvider; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension; @@ -33,6 +34,10 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('fd.symfony.log.viewer.log_files_config.home_route', $mergedConfigs['home_route'] ?? null); + if ($mergedConfigs['show_performance_details'] === false) { + $container->getDefinition(LogRecordsOutputProvider::class)->setArgument('$performanceService', null); + } + foreach ($mergedConfigs['log_files'] as $key => $config) { $container->register('fd.symfony.log.viewer.log_files_config.finder.' . $key, FinderConfig::class) ->setPublic(false) diff --git a/src/Entity/Output/LogRecordsOutput.php b/src/Entity/Output/LogRecordsOutput.php index a4e7c67f..d6b5c7ae 100644 --- a/src/Entity/Output/LogRecordsOutput.php +++ b/src/Entity/Output/LogRecordsOutput.php @@ -15,7 +15,7 @@ class LogRecordsOutput implements JsonSerializable public function __construct( private readonly array $records, private readonly ?Paginator $paginator, - private readonly PerformanceStats $performance + private readonly ?PerformanceStats $performance ) { } diff --git a/src/Service/File/LogRecordsOutputProvider.php b/src/Service/File/LogRecordsOutputProvider.php index df94d142..652dcab2 100644 --- a/src/Service/File/LogRecordsOutputProvider.php +++ b/src/Service/File/LogRecordsOutputProvider.php @@ -19,7 +19,7 @@ class LogRecordsOutputProvider public function __construct( private readonly LogFileParserProvider $logParserProvider, private readonly LogRecordsNormalizer $logRecordsNormalizer, - private readonly PerformanceService $performanceService, + private readonly ?PerformanceService $performanceService, ) { } @@ -44,7 +44,7 @@ public function provideForFiles(array $files, LogQueryDto $logQuery): LogRecords return new LogRecordsOutput( $this->logRecordsNormalizer->normalize($logRecordCollection->getRecords(), $logQuery->timeZone), $logRecordCollection->getPaginator(), - $this->performanceService->getPerformanceStats() + $this->performanceService?->getPerformanceStats() ); } @@ -56,7 +56,7 @@ public function provide(LogFile $file, LogQueryDto $logQuery): LogRecordsOutput return new LogRecordsOutput( $this->logRecordsNormalizer->normalize($logRecordCollection->getRecords(), $logQuery->timeZone), $logRecordCollection->getPaginator(), - $this->performanceService->getPerformanceStats() + $this->performanceService?->getPerformanceStats() ); } } diff --git a/tests/Integration/DependencyInjection/data/expected-default-config.json b/tests/Integration/DependencyInjection/data/expected-default-config.json index c1c1cfff..f8e1c1e7 100644 --- a/tests/Integration/DependencyInjection/data/expected-default-config.json +++ b/tests/Integration/DependencyInjection/data/expected-default-config.json @@ -1,4 +1,5 @@ { + "show_performance_details": true, "log_files": { "monolog": { "type": "monolog", diff --git a/tests/Integration/DependencyInjection/data/expected-hosts-override-config.json b/tests/Integration/DependencyInjection/data/expected-hosts-override-config.json index 8c3d545b..357f94bb 100644 --- a/tests/Integration/DependencyInjection/data/expected-hosts-override-config.json +++ b/tests/Integration/DependencyInjection/data/expected-hosts-override-config.json @@ -11,6 +11,7 @@ } } }, + "show_performance_details": true, "log_files": { "monolog": { "type": "monolog", diff --git a/tests/Integration/DependencyInjection/data/expected-merge-monolog-config.json b/tests/Integration/DependencyInjection/data/expected-merge-monolog-config.json index a83304fd..e3c57a94 100644 --- a/tests/Integration/DependencyInjection/data/expected-merge-monolog-config.json +++ b/tests/Integration/DependencyInjection/data/expected-merge-monolog-config.json @@ -17,6 +17,7 @@ "date_format": null } }, + "show_performance_details": true, "hosts": { "localhost": { "name": "Local", diff --git a/tests/Integration/DependencyInjection/data/expected-override-monolog-config.json b/tests/Integration/DependencyInjection/data/expected-override-monolog-config.json index 756402f8..9d5d9e69 100644 --- a/tests/Integration/DependencyInjection/data/expected-override-monolog-config.json +++ b/tests/Integration/DependencyInjection/data/expected-override-monolog-config.json @@ -16,6 +16,7 @@ "date_format": null } }, + "show_performance_details": true, "hosts": { "localhost": { "name": "Local", diff --git a/tests/Integration/DependencyInjection/data/full-config.json b/tests/Integration/DependencyInjection/data/full-config.json index 5ab73fae..20eb4be9 100644 --- a/tests/Integration/DependencyInjection/data/full-config.json +++ b/tests/Integration/DependencyInjection/data/full-config.json @@ -1,6 +1,7 @@ { "fd_log_viewer": { "home_route": "home", + "show_performance_details": true, "log_files": { "monolog": { "type": "monolog",