From 492ce579538dc3672ac4bcc6ab3cc6e3fe789961 Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Fri, 22 Dec 2023 10:24:25 +0100 Subject: [PATCH] MOL-1206: create plugin config for log file retention days --- src/Resources/config/config.xml | 10 ++++++++ src/Resources/config/services/services.xml | 1 - src/Service/Logger/MollieLoggerFactory.php | 12 +++------- src/Setting/MollieSettingStruct.php | 28 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml index 5d2e07abc..d06a1063e 100644 --- a/src/Resources/config/config.xml +++ b/src/Resources/config/config.xml @@ -49,6 +49,16 @@ Mollie hat eine eigene LOG Datei im Shopware Log Verzeichnis. Dieser Modus kümmert sich um erweiterte Informationen in diesen Log Dateien, die zusätzlich bei der Analyse von Fehlern beitragen können. Mollie heeft een op maat logbestand in de Shopware logboek-map. Deze functie maakt uitgebreide logs mogelijk met meer informatie die helpen bij het oplossen van problemen. + + logFileDays + + + + 14 + Set the number of days how long log files are kept until they will be automatically deleted. + Legen Sie die Anzahl der Tage fest, wie lange Protokolldateien aufbewahrt werden, bis sie automatisch gelöscht werden. + Stel het aantal dagen in hoe lang logbestanden worden bewaard totdat ze automatisch worden verwijderd. + molliePluginConfigSectionApi diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml index 0cbb2982d..f2859303a 100644 --- a/src/Resources/config/services/services.xml +++ b/src/Resources/config/services/services.xml @@ -9,7 +9,6 @@ %kernel.logs_dir%/mollie_%kernel.environment%.log - 14 %env(DATABASE_URL)% diff --git a/src/Service/Logger/MollieLoggerFactory.php b/src/Service/Logger/MollieLoggerFactory.php index 39d746d99..0587792fc 100644 --- a/src/Service/Logger/MollieLoggerFactory.php +++ b/src/Service/Logger/MollieLoggerFactory.php @@ -31,11 +31,6 @@ class MollieLoggerFactory */ private $filename; - /** - * @var string - */ - private $retentionDays; - /** * @var string */ @@ -45,14 +40,12 @@ class MollieLoggerFactory /** * @param SettingsService $settingsService * @param string $filename - * @param string $retentionDays * @param string $dsn */ - public function __construct(SettingsService $settingsService, string $filename, string $retentionDays, string $dsn) + public function __construct(SettingsService $settingsService, string $filename, string $dsn) { $this->settingsService = $settingsService; $this->filename = $filename; - $this->retentionDays = $retentionDays; $this->dsn = $dsn; } @@ -70,8 +63,9 @@ public function createLogger(): LoggerInterface # 100 = DEBUG, 200 = INFO $minLevel = ($config->isDebugMode()) ? 100 : 200; + $retentionDays = $config->getLogFileDays(); - $fileHandler = new RotatingFileHandler($this->filename, (int)$this->retentionDays, $minLevel); + $fileHandler = new RotatingFileHandler($this->filename, $retentionDays, $minLevel); $processors = []; $processors[] = new AnonymousWebProcessor(new WebProcessor(), new URLAnonymizer()); diff --git a/src/Setting/MollieSettingStruct.php b/src/Setting/MollieSettingStruct.php index 9d1249c1f..088c1547a 100644 --- a/src/Setting/MollieSettingStruct.php +++ b/src/Setting/MollieSettingStruct.php @@ -51,6 +51,11 @@ class MollieSettingStruct extends Struct */ protected $debugMode = false; + /** + * @var int + */ + protected $logFileDays = 0; + /** * @var bool */ @@ -322,6 +327,29 @@ public function setTestMode(bool $testMode): self return $this; } + /** + * @return int + */ + public function getLogFileDays(): int + { + if ($this->logFileDays === 0) { + // better be safe than sorry, default was always 14 + return 14; + } + + return $this->logFileDays; + } + + /** + * @param int $logFileDays + * @return void + */ + public function setLogFileDays(int $logFileDays): void + { + $this->logFileDays = $logFileDays; + } + + /** * @return bool */