Mysql log retain

This commit is contained in:
Juan Pablo Vial
2024-06-07 17:18:20 -04:00
parent b27a6fab33
commit 27e88761e0

View File

@ -12,7 +12,7 @@ class MySQLHandler extends AbstractProcessingHandler
private bool $initialized = false; private bool $initialized = false;
private PDOStatement $statement; private PDOStatement $statement;
public function __construct(protected Connection $connection, int|string|Level $level = Level::Debug, bool $bubble = true) public function __construct(protected Connection $connection, protected int $retainDays = 90, int|string|Level $level = Level::Debug, bool $bubble = true)
{ {
parent::__construct($level, $bubble); parent::__construct($level, $bubble);
} }
@ -54,7 +54,7 @@ QUERY;
} }
private function cleanup(): void private function cleanup(): void
{ {
$query = "DELETE FROM monolog WHERE time < DATE_SUB(CURDATE(), INTERVAL 90 DAY)"; $query = "DELETE FROM monolog WHERE time < DATE_SUB(CURDATE(), INTERVAL {$this->retainDays} DAY)";
$this->connection->query($query); $this->connection->query($query);
} }
} }