From 95c437efd5c9b72d9dbd15c385699f53620bdc1c Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sat, 27 Mar 2021 18:53:29 +0430 Subject: [PATCH] better logging --- .../main/kotlin/ir/armor/tachidesk/impl/Extension.kt | 10 +++++----- .../kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt | 4 ++-- .../main/kotlin/ir/armor/tachidesk/impl/SourceList.kt | 6 +++--- .../kotlin/ir/armor/tachidesk/server/ServerSetup.kt | 11 +++++++---- .../ir/armor/tachidesk/server/util/SystemTray.kt | 3 ++- server/src/main/resources/logback.xml | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt index 68cc1b9..b8a98e4 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt @@ -71,7 +71,7 @@ private fun dex2jar(dexFile: String, jarFile: String, fileNameWithoutType: Strin } fun installAPK(apkName: String): Int { - logger.info("Installing $apkName") + logger.debug("Installing $apkName") val extensionRecord = getExtensionList(true).first { it.apkName == apkName } val fileNameWithoutType = apkName.substringBefore(".apk") val dirPathWithoutType = "${applicationDirs.extensionsRoot}/$fileNameWithoutType" @@ -91,7 +91,7 @@ fun installAPK(apkName: String): Int { downloadAPKFile(apkToDownload, apkFilePath) val className: String = APKExtractor.extract_dex_and_read_className(apkFilePath, dexFilePath) - logger.info(className) + logger.debug(className) // dex -> jar dex2jar(dexFilePath, jarFilePath, fileNameWithoutType) @@ -119,7 +119,7 @@ fun installAPK(apkName: String): Int { it[extension] = extensionId } } - logger.info("Installed source ${httpSource.name} with id {httpSource.id}") + logger.debug("Installed source ${httpSource.name} with id {httpSource.id}") } } else { // multi source val sourceFactory = instance as SourceFactory @@ -136,7 +136,7 @@ fun installAPK(apkName: String): Int { it[positionInFactorySource] = index } } - logger.info("Installed source ${httpSource.name} with id:${httpSource.id}") + logger.debug("Installed source ${httpSource.name} with id:${httpSource.id}") } } } @@ -168,7 +168,7 @@ private fun downloadAPKFile(url: String, apkPath: String) { } fun removeExtension(apkName: String) { - logger.info("Uninstalling $apkName") + logger.debug("Uninstalling $apkName") val extensionRecord = getExtensionList(true).first { it.apkName == apkName } val fileNameWithoutType = apkName.substringBefore(".apk") diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt index e1e9d3f..1fdc668 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt @@ -34,7 +34,7 @@ private fun extensionDatabaseIsEmtpy(): Boolean { fun getExtensionList(offline: Boolean = false): List { // update if 60 seconds has passed or requested offline and database is empty if (Data.lastExtensionCheck + 60 * 1000 < System.currentTimeMillis() || (offline && extensionDatabaseIsEmtpy())) { - logger.info("Getting extensions list from the internet") + logger.debug("Getting extensions list from the internet") Data.lastExtensionCheck = System.currentTimeMillis() var foundExtensions: List runBlocking { @@ -72,7 +72,7 @@ fun getExtensionList(offline: Boolean = false): List { } } } else { - logger.info("used cached extension list") + logger.debug("used cached extension list") } return transaction { diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt index de332b8..a528bd6 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt @@ -35,7 +35,7 @@ fun getHttpSource(sourceId: Long): HttpSource { val cachedResult: Pair? = sourceCache.firstOrNull { it.first == sourceId } if (cachedResult != null) { - logger.info("used cached HttpSource: ${cachedResult.second.name}") + logger.debug("used cached HttpSource: ${cachedResult.second.name}") return cachedResult.second } @@ -52,10 +52,10 @@ fun getHttpSource(sourceId: Long): HttpSource { val instance = if (cachedExtensionPair != null) { usedCached = true - logger.info("Used cached Extension") + logger.debug("Used cached Extension") cachedExtensionPair.second } else { - logger.info("No Extension cache") + logger.debug("No Extension cache") val child = URLClassLoader(arrayOf(URL("file:$jarPath")), this::class.java.classLoader) val classToLoad = Class.forName(className, true, child) classToLoad.newInstance() diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt index b9cfd71..5fb1f69 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt @@ -40,6 +40,12 @@ fun applicationSetup() { ServerConfig.register(GlobalConfigManager.config) ) + // set application wide logging level + if (serverConfig.debugLogsEnabled) { +// (mu.KotlinLogging.logger("ir.armor.tachidesk").underlyingLogger as ch.qos.logback.classic.Logger).level = Level.DEBUG + (mu.KotlinLogging.logger(org.slf4j.Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger).level = Level.DEBUG + } + // make dirs we need listOf( applicationDirs.dataRoot, @@ -83,11 +89,8 @@ fun applicationSetup() { // start app androidCompat.startApp(App()) - // set application wide logging level - if (!serverConfig.debugLogsEnabled) - (mu.KotlinLogging.logger("ir.armor.tachidesk").underlyingLogger as ch.qos.logback.classic.Logger).level = Level.INFO - // Disable jetty's logging + System.setProperty("org.eclipse.jetty.util.log.announce", "false") System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog") System.setProperty("org.eclipse.jetty.LEVEL", "OFF") diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt index f053885..08fc4e8 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt @@ -13,6 +13,7 @@ import dorkbox.systemTray.SystemTray.TrayType import dorkbox.util.CacheUtil import dorkbox.util.Desktop import ir.armor.tachidesk.Main +import ir.armor.tachidesk.server.serverConfig import java.awt.event.ActionListener import java.io.IOException @@ -27,7 +28,7 @@ fun openInBrowser() { fun systemTray(): SystemTray? { try { // ref: https://github.com/dorkbox/SystemTray/blob/master/test/dorkbox/TestTray.java - SystemTray.DEBUG = false + SystemTray.DEBUG = serverConfig.debugLogsEnabled if (System.getProperty("os.name").startsWith("Windows")) SystemTray.FORCE_TRAY_TYPE = TrayType.Swing diff --git a/server/src/main/resources/logback.xml b/server/src/main/resources/logback.xml index 7e9d0aa..d7307c1 100644 --- a/server/src/main/resources/logback.xml +++ b/server/src/main/resources/logback.xml @@ -8,9 +8,9 @@ - + - + \ No newline at end of file