initialized) { if (!$this->checkTableExists()) { $this->createTable(); } if (!$this->checkTableDeprecatedExists()) { $this->createTableDeprecated(); } $this->cleanup(); $this->cleanupDeprecated(); $this->initialized(); } if (str_contains(strtolower($record->message), 'deprecated:')) { $this->statementDeprecated->execute([ 'channel' => $record->channel, 'level' => $record->level->getName(), 'message' => $record->formatted, 'time' => $record->datetime->format('Y-m-d H:i:s.u'), 'context' => (count($record->context) > 0) ? json_encode($record->context, JSON_UNESCAPED_SLASHES) : '', 'extra' => (count($record->extra) > 0) ? json_encode($record->extra, JSON_UNESCAPED_SLASHES) : '' ]); return; } $this->statement->execute([ 'channel' => $record->channel, 'level' => $record->level->getName(), 'message' => $record->formatted, 'time' => $record->datetime->format('Y-m-d H:i:s.u'), 'context' => (count($record->context) > 0) ? json_encode($record->context, JSON_UNESCAPED_SLASHES) : '', 'extra' => (count($record->extra) > 0) ? json_encode($record->extra, JSON_UNESCAPED_SLASHES) : '' ]); } private function initialized(): void { $query = <<statement = $this->connection->getPDO()->prepare($query); $query = <<statementDeprecated = $this->connection->getPDO()->prepare($query); $this->initialized = true; } private function checkTableExists(): bool { $query = "SHOW TABLES LIKE 'monolog'"; try { $result = $this->connection->query($query); } catch (PDOException) { return false; } return $result->rowCount() > 0; } private function checkTableDeprecatedExists(): bool { $query = "SHOW TABLES LIKE 'monolog_deprecated'"; try { $result = $this->connection->query($query); } catch (PDOException) { return false; } return $result->rowCount() > 0; } private function createTable(): void { $query = <<connection->getPDO()->exec($query); } private function createTableDeprecated(): void { $query = <<connection->query($query); } private function cleanupDeprecated(): void { $query = "DELETE FROM monolog_deprecated WHERE time < DATE_SUB(CURDATE(), INTERVAL {$this->retainDays} DAY)"; } }