mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-23 21:12:37 +01:00
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:
@@ -79,7 +79,7 @@ open class ConfigManager {
|
|||||||
|
|
||||||
// set log level early
|
// set log level early
|
||||||
if (debugLogsEnabled(config)) {
|
if (debugLogsEnabled(config)) {
|
||||||
setLogLevel(Level.DEBUG)
|
setLogLevelFor(BASE_LOGGER_NAME, Level.DEBUG)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
@@ -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)
|
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) {
|
fun initLoggerConfig(appRootPath: String) {
|
||||||
val context = LoggerFactory.getILoggerFactory() as LoggerContext
|
val context = LoggerFactory.getILoggerFactory() as LoggerContext
|
||||||
val logger = getBaseLogger()
|
val logger = getBaseLogger()
|
||||||
@@ -62,11 +67,19 @@ fun initLoggerConfig(appRootPath: String) {
|
|||||||
logger.addAppender(createRollingFileAppender(context, "$appRootPath/logs"))
|
logger.addAppender(createRollingFileAppender(context, "$appRootPath/logs"))
|
||||||
|
|
||||||
// set "kotlin exposed" log level
|
// set "kotlin exposed" log level
|
||||||
context.getLogger("Exposed").level = Level.ERROR
|
setLogLevelFor("Exposed", Level.ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLogLevel(level: Level) {
|
const val BASE_LOGGER_NAME = "_BaseLogger"
|
||||||
getBaseLogger().level = level
|
|
||||||
|
fun setLogLevelFor(name: String, level: Level) {
|
||||||
|
val logger = if (name == BASE_LOGGER_NAME) {
|
||||||
|
getBaseLogger()
|
||||||
|
} else {
|
||||||
|
getLogger(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.level = level
|
||||||
}
|
}
|
||||||
|
|
||||||
fun debugLogsEnabled(config: Config) =
|
fun debugLogsEnabled(config: Config) =
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
|
|||||||
|
|
||||||
// misc
|
// misc
|
||||||
val debugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
val debugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
|
val gqlDebugLogsEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
val systemTrayEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
val systemTrayEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
|
|
||||||
// backup
|
// backup
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.App
|
|||||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||||
import io.javalin.plugin.json.JavalinJackson
|
import io.javalin.plugin.json.JavalinJackson
|
||||||
import io.javalin.plugin.json.JsonMapper
|
import io.javalin.plugin.json.JsonMapper
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
@@ -32,10 +33,11 @@ import suwayomi.tachidesk.server.util.SystemTray
|
|||||||
import xyz.nulldev.androidcompat.AndroidCompat
|
import xyz.nulldev.androidcompat.AndroidCompat
|
||||||
import xyz.nulldev.androidcompat.AndroidCompatInitializer
|
import xyz.nulldev.androidcompat.AndroidCompatInitializer
|
||||||
import xyz.nulldev.ts.config.ApplicationRootDir
|
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.ConfigKodeinModule
|
||||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||||
import xyz.nulldev.ts.config.initLoggerConfig
|
import xyz.nulldev.ts.config.initLoggerConfig
|
||||||
import xyz.nulldev.ts.config.setLogLevel
|
import xyz.nulldev.ts.config.setLogLevelFor
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.security.Security
|
import java.security.Security
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -73,19 +75,26 @@ fun applicationSetup() {
|
|||||||
ServerConfig.register { GlobalConfigManager.config }
|
ServerConfig.register { GlobalConfigManager.config }
|
||||||
)
|
)
|
||||||
|
|
||||||
serverConfig.subscribeTo(serverConfig.debugLogsEnabled, { debugLogsEnabled ->
|
|
||||||
if (debugLogsEnabled) {
|
|
||||||
setLogLevel(Level.DEBUG)
|
|
||||||
} else {
|
|
||||||
setLogLevel(Level.INFO)
|
|
||||||
}
|
|
||||||
}, ignoreInitialValue = false)
|
|
||||||
|
|
||||||
// Application dirs
|
// Application dirs
|
||||||
val applicationDirs = ApplicationDirs()
|
val applicationDirs = ApplicationDirs()
|
||||||
|
|
||||||
initLoggerConfig(applicationDirs.dataRoot)
|
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.info("Running Tachidesk ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}")
|
||||||
|
|
||||||
logger.debug {
|
logger.debug {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ server.basicAuthPassword = ""
|
|||||||
|
|
||||||
# misc
|
# misc
|
||||||
server.debugLogsEnabled = false
|
server.debugLogsEnabled = false
|
||||||
|
server.gqlDebugLogsEnabled = false # this includes logs with non privacy safe information
|
||||||
server.systemTrayEnabled = true
|
server.systemTrayEnabled = true
|
||||||
|
|
||||||
# backup
|
# backup
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ server.globalUpdateInterval = 12
|
|||||||
|
|
||||||
# misc
|
# misc
|
||||||
server.debugLogsEnabled = true
|
server.debugLogsEnabled = true
|
||||||
|
server.gqlDebugLogsEnabled = false
|
||||||
server.systemTrayEnabled = false
|
server.systemTrayEnabled = false
|
||||||
|
|
||||||
# webUI
|
# webUI
|
||||||
|
|||||||
Reference in New Issue
Block a user