Feature/graphql logging (#674)

* Set graphql logs to error level

Set log level for loggers with names
 - ExecutionStrategy (spams logs with "... completing field ...")
 - notprivacysafe (logs every received request up to 4 times (received, parse, validate, execute))

* Extract logic to get logger for name into function

* Add function to set log level for a logger

* Add settings to enable graphql debug logging
This commit is contained in:
schroda
2023-09-04 00:10:43 +02:00
committed by GitHub
parent 1c9a139006
commit 56deea9fb3
6 changed files with 38 additions and 13 deletions
@@ -90,6 +90,7 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
// misc
val debugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val gqlDebugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val systemTrayEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
// backup
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.source.local.LocalSource
import io.javalin.plugin.json.JavalinJackson
import io.javalin.plugin.json.JsonMapper
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.serialization.json.Json
import mu.KotlinLogging
@@ -32,10 +33,11 @@ import suwayomi.tachidesk.server.util.SystemTray
import xyz.nulldev.androidcompat.AndroidCompat
import xyz.nulldev.androidcompat.AndroidCompatInitializer
import xyz.nulldev.ts.config.ApplicationRootDir
import xyz.nulldev.ts.config.BASE_LOGGER_NAME
import xyz.nulldev.ts.config.ConfigKodeinModule
import xyz.nulldev.ts.config.GlobalConfigManager
import xyz.nulldev.ts.config.initLoggerConfig
import xyz.nulldev.ts.config.setLogLevel
import xyz.nulldev.ts.config.setLogLevelFor
import java.io.File
import java.security.Security
import java.util.Locale
@@ -73,19 +75,26 @@ fun applicationSetup() {
ServerConfig.register { GlobalConfigManager.config }
)
serverConfig.subscribeTo(serverConfig.debugLogsEnabled, { debugLogsEnabled ->
if (debugLogsEnabled) {
setLogLevel(Level.DEBUG)
} else {
setLogLevel(Level.INFO)
}
}, ignoreInitialValue = false)
// Application dirs
val applicationDirs = ApplicationDirs()
initLoggerConfig(applicationDirs.dataRoot)
val setupLogLevelUpdating = { configFlow: MutableStateFlow<Boolean>, loggerNames: List<String> ->
serverConfig.subscribeTo(configFlow, { debugLogsEnabled ->
if (debugLogsEnabled) {
loggerNames.forEach { loggerName -> setLogLevelFor(loggerName, Level.DEBUG) }
} else {
loggerNames.forEach { loggerName -> setLogLevelFor(loggerName, Level.ERROR) }
}
}, ignoreInitialValue = false)
}
setupLogLevelUpdating(serverConfig.debugLogsEnabled, listOf(BASE_LOGGER_NAME))
// gql "ExecutionStrategy" spams logs with "... completing field ..."
// gql "notprivacysafe" logs every received request multiple times (received, parsing, validating, executing)
setupLogLevelUpdating(serverConfig.gqlDebugLogsEnabled, listOf("graphql", "notprivacysafe"))
logger.info("Running Tachidesk ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}")
logger.debug {
@@ -37,6 +37,7 @@ server.basicAuthPassword = ""
# misc
server.debugLogsEnabled = false
server.gqlDebugLogsEnabled = false # this includes logs with non privacy safe information
server.systemTrayEnabled = true
# backup
@@ -22,6 +22,7 @@ server.globalUpdateInterval = 12
# misc
server.debugLogsEnabled = true
server.gqlDebugLogsEnabled = false
server.systemTrayEnabled = false
# webUI