Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOL-1206: create plugin config for log file retention days #674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 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
Loading