diff --git a/config/packages/monolog.yaml b/config/packages/monolog.yaml index 39ed74a..7c55740 100644 --- a/config/packages/monolog.yaml +++ b/config/packages/monolog.yaml @@ -3,7 +3,8 @@ monolog: handlers: agent: - type: stream + type: rotating_file path: '%kernel.logs_dir%/agent.log' level: debug - channels: ['agent'] + max_files: 14 + channels: ['agent'] \ No newline at end of file diff --git a/src/Controller/Admin/AdminVectorLogController.php b/src/Controller/Admin/AdminVectorLogController.php new file mode 100644 index 0000000..7ce1bf1 --- /dev/null +++ b/src/Controller/Admin/AdminVectorLogController.php @@ -0,0 +1,69 @@ +denyAccessUnlessGranted('ROLE_SUPER_ADMIN'); + + // ⚠️ Pfad ggf. anpassen falls bei dir anders konfiguriert + $logFile = \dirname(__DIR__, 3) . '/var/log/vector_service.log'; + + if (!\file_exists($logFile)) { + return $this->render('admin/vector/log.html.twig', [ + 'content' => 'vector_service.log not found.', + 'fileExists' => false, + ]); + } + + $content = $this->readLastLines($logFile, 500); + + return $this->render('admin/vector/log.html.twig', [ + 'content' => $content, + 'fileExists' => true, + ]); + } + + /** + * Read last N lines safely (memory-friendly) + */ + private function readLastLines(string $file, int $lines = 500): string + { + $handle = \fopen($file, 'rb'); + if (!$handle) { + return 'Unable to open log file.'; + } + + $buffer = ''; + $chunkSize = 4096; + $lineCount = 0; + $pos = -1; + + \fseek($handle, 0, SEEK_END); + $fileSize = \ftell($handle); + + while ($lineCount < $lines && -$pos < $fileSize) { + $step = \min($chunkSize, $fileSize + $pos); + \fseek($handle, $pos - $step, SEEK_END); + $chunk = \fread($handle, $step); + $buffer = $chunk . $buffer; + $lineCount += \substr_count($chunk, "\n"); + $pos -= $step; + } + + \fclose($handle); + + $linesArray = \explode("\n", $buffer); + return \implode("\n", \array_slice($linesArray, -$lines)); + } +} \ No newline at end of file diff --git a/templates/admin/base.html.twig b/templates/admin/base.html.twig index d5b2f61..c86f044 100644 --- a/templates/admin/base.html.twig +++ b/templates/admin/base.html.twig @@ -61,7 +61,7 @@
{{ content }}
+ {% endif %}
+