mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Feature/update log file rotation (#1023)
* Keep up to 31 log files On average one log file per day gets created, thus, increasing to 31 files will store log files for one month * Decrease total log files size to 100mb * Make log appender settings configurable
This commit is contained in:
@@ -9,6 +9,24 @@ import suwayomi.tachidesk.server.ServerConfig
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||
|
||||
private fun validateString(
|
||||
value: String?,
|
||||
pattern: Regex,
|
||||
name: String,
|
||||
) {
|
||||
validateString(value, pattern, Exception("Invalid format for \"$name\" [$value]"))
|
||||
}
|
||||
|
||||
private fun validateString(
|
||||
value: String?,
|
||||
pattern: Regex,
|
||||
exception: Exception,
|
||||
) {
|
||||
if (value != null && !value.matches(pattern)) {
|
||||
throw exception
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsMutation {
|
||||
data class SetSettingsInput(
|
||||
val clientMutationId: String? = null,
|
||||
@@ -20,6 +38,13 @@ class SettingsMutation {
|
||||
val settings: SettingsType,
|
||||
)
|
||||
|
||||
private fun validateSettings(settings: Settings) {
|
||||
// misc
|
||||
val logbackSizePattern = "^[0-9]+(|kb|KB|mb|MB|gb|GB)\$".toRegex()
|
||||
validateString(settings.maxLogFileSize, logbackSizePattern, "maxLogFileSize")
|
||||
validateString(settings.maxLogFolderSize, logbackSizePattern, "maxLogFolderSize")
|
||||
}
|
||||
|
||||
private fun <SettingType : Any> updateSetting(
|
||||
newSetting: SettingType?,
|
||||
configSetting: MutableStateFlow<SettingType>,
|
||||
@@ -82,6 +107,9 @@ class SettingsMutation {
|
||||
updateSetting(settings.debugLogsEnabled, serverConfig.debugLogsEnabled)
|
||||
updateSetting(settings.gqlDebugLogsEnabled, serverConfig.gqlDebugLogsEnabled)
|
||||
updateSetting(settings.systemTrayEnabled, serverConfig.systemTrayEnabled)
|
||||
updateSetting(settings.maxLogFiles, serverConfig.maxLogFiles)
|
||||
updateSetting(settings.maxLogFileSize, serverConfig.maxLogFileSize)
|
||||
updateSetting(settings.maxLogFolderSize, serverConfig.maxLogFolderSize)
|
||||
|
||||
// backup
|
||||
updateSetting(settings.backupPath, serverConfig.backupPath)
|
||||
@@ -104,6 +132,7 @@ class SettingsMutation {
|
||||
fun setSettings(input: SetSettingsInput): SetSettingsPayload {
|
||||
val (clientMutationId, settings) = input
|
||||
|
||||
validateSettings(settings)
|
||||
updateSettings(settings)
|
||||
|
||||
return SetSettingsPayload(clientMutationId, SettingsType())
|
||||
|
||||
@@ -73,6 +73,9 @@ interface Settings : Node {
|
||||
val debugLogsEnabled: Boolean?
|
||||
val gqlDebugLogsEnabled: Boolean?
|
||||
val systemTrayEnabled: Boolean?
|
||||
val maxLogFiles: Int?
|
||||
val maxLogFileSize: String?
|
||||
val maxLogFolderSize: String?
|
||||
|
||||
// backup
|
||||
val backupPath: String?
|
||||
@@ -139,6 +142,9 @@ data class PartialSettingsType(
|
||||
override val debugLogsEnabled: Boolean?,
|
||||
override val gqlDebugLogsEnabled: Boolean?,
|
||||
override val systemTrayEnabled: Boolean?,
|
||||
override val maxLogFiles: Int?,
|
||||
override val maxLogFileSize: String?,
|
||||
override val maxLogFolderSize: String?,
|
||||
// backup
|
||||
override val backupPath: String?,
|
||||
override val backupTime: String?,
|
||||
@@ -202,6 +208,9 @@ class SettingsType(
|
||||
override val debugLogsEnabled: Boolean,
|
||||
override val gqlDebugLogsEnabled: Boolean,
|
||||
override val systemTrayEnabled: Boolean,
|
||||
override val maxLogFiles: Int,
|
||||
override val maxLogFileSize: String,
|
||||
override val maxLogFolderSize: String,
|
||||
// backup
|
||||
override val backupPath: String,
|
||||
override val backupTime: String,
|
||||
@@ -260,6 +269,9 @@ class SettingsType(
|
||||
config.debugLogsEnabled.value,
|
||||
config.gqlDebugLogsEnabled.value,
|
||||
config.systemTrayEnabled.value,
|
||||
config.maxLogFiles.value,
|
||||
config.maxLogFileSize.value,
|
||||
config.maxLogFolderSize.value,
|
||||
// backup
|
||||
config.backupPath.value,
|
||||
config.backupTime.value,
|
||||
|
||||
Reference in New Issue
Block a user