Skip to content

Commit

Permalink
MOL-1206: create plugin config for log file retention days
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 22, 2023
1 parent 5511d15 commit a3c9045
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
<helpText lang="de-DE">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.</helpText>
<helpText lang="nl-NL">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.</helpText>
</input-field>
<input-field type="int">
<name>logFileDays</name>
<label>Keep log files (days)</label>
<label lang="de-DE">Log-Dateien aufbewahren (Tage)</label>
<label lang="nl-NL">Logbestanden bijhouden (dagen)</label>
<defaultValue>14</defaultValue>
<helpText>Set the number of days how long log files are kept until they will be automatically deleted.</helpText>
<helpText lang="de-DE">Legen Sie die Anzahl der Tage fest, wie lange Protokolldateien aufbewahrt werden, bis sie automatisch gelöscht werden.</helpText>
<helpText lang="nl-NL">Stel het aantal dagen in hoe lang logbestanden worden bewaard totdat ze automatisch worden verwijderd.</helpText>
</input-field>
<component name="mollie-pluginconfig-section-api">
<name>molliePluginConfigSectionApi</name>
</component>
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<service id="Kiener\MolliePayments\Service\Logger\MollieLoggerFactory" class="Kiener\MolliePayments\Service\Logger\MollieLoggerFactory">
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument>%kernel.logs_dir%/mollie_%kernel.environment%.log</argument>
<argument>14</argument>
<argument>%env(DATABASE_URL)%</argument>
</service>

Expand Down
12 changes: 3 additions & 9 deletions src/Service/Logger/MollieLoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class MollieLoggerFactory
*/
private $filename;

/**
* @var string
*/
private $retentionDays;

/**
* @var string
*/
Expand All @@ -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;
}

Expand All @@ -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());
Expand Down
32 changes: 30 additions & 2 deletions src/Setting/MollieSettingStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class MollieSettingStruct extends Struct
*/
protected $debugMode = false;

/**
* @var int
*/
protected $logFileDays = 0;

/**
* @var bool
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -489,8 +517,8 @@ public function getPaymentMethodBankTransferDueDateDays(): ?int
/**
* returns bank transfer due date in YYYY-MM-DD format or null
*
* @throws Exception
* @return null|string
* @throws Exception
*/
public function getPaymentMethodBankTransferDueDate(): ?string
{
Expand Down Expand Up @@ -523,8 +551,8 @@ public function getOrderLifetimeDays(): ?int
}

/**
* @throws Exception
* @return string
* @throws Exception
*/
public function getOrderLifetimeDate(): ?string
{
Expand Down

0 comments on commit a3c9045

Please sign in to comment.