mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -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())
|
||||
|
||||
Reference in New Issue
Block a user