Skip to content

Commit 61e0ebc

Browse files
authored
Add ability to toggle performance stats visibility (#288)
Co-authored-by: frankdekker <2179983+frankdekker@users.noreply.github.com>
1 parent 03d1f5f commit 61e0ebc

File tree

11 files changed

+26
-4
lines changed

11 files changed

+26
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Default configuration: [(Configuration reference)](https://github.com/frankdekke
8686
```yaml
8787
fd_log_viewer:
8888
home_route: null
89+
show_performance_details: true
8990

9091
log_files:
9192
monolog:

docs/configuration-reference.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Out of the box, [Log viewer](../README.md) will have the following configuration
77
```yaml
88
fd_log_viewer:
99
home_route: null
10+
show_performance_details: true
1011

1112
log_files:
1213
monolog:
@@ -39,6 +40,12 @@ fd_log_viewer:
3940
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/`.
4041
<br><br>
4142

43+
### show_performance_details
44+
type: `boolean`. Default: `true`
45+
46+
Show the performance details (memory, duration and package version) in the footer or not.
47+
<br><br>
48+
4249
### log_files
4350

4451
**type**: `array<string, mixed>`

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function getConfigTreeBuilder(): TreeBuilder
2626
$rootNode
2727
->children()
2828
->scalarNode('home_route')->info("The name of the route to redirect to when clicking the back button")->end()
29+
->scalarNode('show_performance_details')
30+
->defaultTrue()
31+
->info("Will toggle if the performance information and version will be shown. Default true")
32+
->end()
2933
->append($this->configureLogFiles())
3034
->append($this->configureHosts());
3135

src/DependencyInjection/Extension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use FD\LogViewer\Entity\Config\HostAuthenticationConfig;
88
use FD\LogViewer\Entity\Config\HostConfig;
99
use FD\LogViewer\Entity\Config\LogFilesConfig;
10+
use FD\LogViewer\Service\File\LogRecordsOutputProvider;
1011
use Symfony\Component\Config\FileLocator;
1112
use Symfony\Component\DependencyInjection\ContainerBuilder;
1213
use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension;
@@ -33,6 +34,10 @@ public function load(array $configs, ContainerBuilder $container): void
3334

3435
$container->setParameter('fd.symfony.log.viewer.log_files_config.home_route', $mergedConfigs['home_route'] ?? null);
3536

37+
if ($mergedConfigs['show_performance_details'] === false) {
38+
$container->getDefinition(LogRecordsOutputProvider::class)->setArgument('$performanceService', null);
39+
}
40+
3641
foreach ($mergedConfigs['log_files'] as $key => $config) {
3742
$container->register('fd.symfony.log.viewer.log_files_config.finder.' . $key, FinderConfig::class)
3843
->setPublic(false)

src/Entity/Output/LogRecordsOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LogRecordsOutput implements JsonSerializable
1515
public function __construct(
1616
private readonly array $records,
1717
private readonly ?Paginator $paginator,
18-
private readonly PerformanceStats $performance
18+
private readonly ?PerformanceStats $performance
1919
) {
2020
}
2121

src/Service/File/LogRecordsOutputProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LogRecordsOutputProvider
1919
public function __construct(
2020
private readonly LogFileParserProvider $logParserProvider,
2121
private readonly LogRecordsNormalizer $logRecordsNormalizer,
22-
private readonly PerformanceService $performanceService,
22+
private readonly ?PerformanceService $performanceService,
2323
) {
2424
}
2525

@@ -44,7 +44,7 @@ public function provideForFiles(array $files, LogQueryDto $logQuery): LogRecords
4444
return new LogRecordsOutput(
4545
$this->logRecordsNormalizer->normalize($logRecordCollection->getRecords(), $logQuery->timeZone),
4646
$logRecordCollection->getPaginator(),
47-
$this->performanceService->getPerformanceStats()
47+
$this->performanceService?->getPerformanceStats()
4848
);
4949
}
5050

@@ -56,7 +56,7 @@ public function provide(LogFile $file, LogQueryDto $logQuery): LogRecordsOutput
5656
return new LogRecordsOutput(
5757
$this->logRecordsNormalizer->normalize($logRecordCollection->getRecords(), $logQuery->timeZone),
5858
$logRecordCollection->getPaginator(),
59-
$this->performanceService->getPerformanceStats()
59+
$this->performanceService?->getPerformanceStats()
6060
);
6161
}
6262
}

tests/Integration/DependencyInjection/data/expected-default-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"show_performance_details": true,
23
"log_files": {
34
"monolog": {
45
"type": "monolog",

tests/Integration/DependencyInjection/data/expected-hosts-override-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
}
1212
}
1313
},
14+
"show_performance_details": true,
1415
"log_files": {
1516
"monolog": {
1617
"type": "monolog",

tests/Integration/DependencyInjection/data/expected-merge-monolog-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"date_format": null
1818
}
1919
},
20+
"show_performance_details": true,
2021
"hosts": {
2122
"localhost": {
2223
"name": "Local",

tests/Integration/DependencyInjection/data/expected-override-monolog-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"date_format": null
1717
}
1818
},
19+
"show_performance_details": true,
1920
"hosts": {
2021
"localhost": {
2122
"name": "Local",

0 commit comments

Comments
 (0)