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

View File

@@ -79,7 +79,7 @@ open class ConfigManager {
// set log level early
if (debugLogsEnabled(config)) {
setLogLevel(Level.DEBUG)
setLogLevelFor(BASE_LOGGER_NAME, Level.DEBUG)
}
return config

View File

@@ -55,6 +55,11 @@ private fun getBaseLogger(): ch.qos.logback.classic.Logger {
return (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
}
private fun getLogger(name: String): ch.qos.logback.classic.Logger {
val context = LoggerFactory.getILoggerFactory() as LoggerContext
return context.getLogger(name)
}
fun initLoggerConfig(appRootPath: String) {
val context = LoggerFactory.getILoggerFactory() as LoggerContext
val logger = getBaseLogger()
@@ -62,11 +67,19 @@ fun initLoggerConfig(appRootPath: String) {
logger.addAppender(createRollingFileAppender(context, "$appRootPath/logs"))
// set "kotlin exposed" log level
context.getLogger("Exposed").level = Level.ERROR
setLogLevelFor("Exposed", Level.ERROR)
}
fun setLogLevel(level: Level) {
getBaseLogger().level = level
const val BASE_LOGGER_NAME = "_BaseLogger"
fun setLogLevelFor(name: String, level: Level) {
val logger = if (name == BASE_LOGGER_NAME) {
getBaseLogger()
} else {
getLogger(name)
}
logger.level = level
}
fun debugLogsEnabled(config: Config) =

View File

@@ -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

View File

@@ -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 {

View File

@@ -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

View File

@@ -22,6 +22,7 @@ server.globalUpdateInterval = 12
# misc
server.debugLogsEnabled = true
server.gqlDebugLogsEnabled = false
server.systemTrayEnabled = false
# webUI