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,
|
||||
|
||||
@@ -125,6 +125,9 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
|
||||
val debugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val gqlDebugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val systemTrayEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val maxLogFiles: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
|
||||
val maxLogFileSize: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
||||
val maxLogFolderSize: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
||||
|
||||
// backup
|
||||
val backupPath: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
||||
|
||||
@@ -45,6 +45,7 @@ import xyz.nulldev.ts.config.ConfigKodeinModule
|
||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||
import xyz.nulldev.ts.config.initLoggerConfig
|
||||
import xyz.nulldev.ts.config.setLogLevelFor
|
||||
import xyz.nulldev.ts.config.updateFileAppender
|
||||
import java.io.File
|
||||
import java.net.Authenticator
|
||||
import java.net.PasswordAuthentication
|
||||
@@ -97,7 +98,28 @@ fun applicationSetup() {
|
||||
// Application dirs
|
||||
val applicationDirs = ApplicationDirs()
|
||||
|
||||
initLoggerConfig(applicationDirs.dataRoot)
|
||||
initLoggerConfig(
|
||||
applicationDirs.dataRoot,
|
||||
serverConfig.maxLogFiles.value,
|
||||
serverConfig.maxLogFileSize.value,
|
||||
serverConfig.maxLogFolderSize.value,
|
||||
)
|
||||
|
||||
serverConfig.subscribeTo(
|
||||
combine(
|
||||
serverConfig.maxLogFiles,
|
||||
serverConfig.maxLogFileSize,
|
||||
serverConfig.maxLogFolderSize,
|
||||
) { maxLogFiles, maxLogFileSize, maxLogFolderSize ->
|
||||
Triple(maxLogFiles, maxLogFileSize, maxLogFolderSize)
|
||||
}.distinctUntilChanged(),
|
||||
{ (maxLogFiles, maxLogFileSize, maxLogFolderSize) ->
|
||||
logger.debug {
|
||||
"updateFileAppender: maxLogFiles= $maxLogFiles, maxLogFileSize= $maxLogFileSize, maxLogFolderSize= $maxLogFolderSize"
|
||||
}
|
||||
updateFileAppender(maxLogFiles, maxLogFileSize, maxLogFolderSize)
|
||||
},
|
||||
)
|
||||
|
||||
setupLogLevelUpdating(serverConfig.debugLogsEnabled, listOf(BASE_LOGGER_NAME))
|
||||
// gql "ExecutionStrategy" spams logs with "... completing field ..."
|
||||
|
||||
@@ -51,6 +51,9 @@ server.basicAuthPassword = ""
|
||||
server.debugLogsEnabled = false
|
||||
server.gqlDebugLogsEnabled = false # this includes logs with non privacy safe information
|
||||
server.systemTrayEnabled = true
|
||||
server.maxLogFiles = 31 # the max number of days to keep files before they get deleted
|
||||
server.maxLogFileSize = "10mb" # the max size of a log file - possible values: 1 (bytes), 1KB (kilobytes), 1MB (megabytes), 1GB (gigabytes)
|
||||
server.maxLogFolderSize = "100mb" # the max size of all saved log files - possible values: 1 (bytes), 1KB (kilobytes), 1MB (megabytes), 1GB (gigabytes)
|
||||
|
||||
# backup
|
||||
server.backupPath = ""
|
||||
|
||||
Reference in New Issue
Block a user