mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
Feature/log to file (#607)
* Setup "logback" to write to file To be able to dynamically set the log file save location, logback has to be setup via code instead of a config file * Log OkHttp via logback Otherwise, the logs would only get written to the console and thus, not be included in the log file * Init logback Has to be done after the config was loaded, otherwise, the root directory would be unknown. Moved the log of the loaded config to the "applicationSetup" since otherwise, the log would not be included in the log file
This commit is contained in:
@@ -17,6 +17,7 @@ package eu.kanade.tachiyomi.network
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
|
||||
import mu.KotlinLogging
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
@@ -43,7 +44,13 @@ class NetworkHelper(context: Context) {
|
||||
.addInterceptor(UserAgentInterceptor())
|
||||
|
||||
if (serverConfig.debugLogsEnabled) {
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
|
||||
val logger = KotlinLogging.logger { }
|
||||
|
||||
override fun log(message: String) {
|
||||
logger.debug { message }
|
||||
}
|
||||
}).apply {
|
||||
level = HttpLoggingInterceptor.Level.BASIC
|
||||
}
|
||||
builder.addInterceptor(httpLoggingInterceptor)
|
||||
|
||||
@@ -7,6 +7,7 @@ package suwayomi.tachidesk.server
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||
import io.javalin.plugin.json.JavalinJackson
|
||||
@@ -30,6 +31,7 @@ import xyz.nulldev.androidcompat.AndroidCompatInitializer
|
||||
import xyz.nulldev.ts.config.ApplicationRootDir
|
||||
import xyz.nulldev.ts.config.ConfigKodeinModule
|
||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||
import xyz.nulldev.ts.config.initLoggerConfig
|
||||
import java.io.File
|
||||
import java.security.Security
|
||||
import java.util.Locale
|
||||
@@ -58,8 +60,6 @@ val systemTrayInstance by lazy { systemTray() }
|
||||
val androidCompat by lazy { AndroidCompat() }
|
||||
|
||||
fun applicationSetup() {
|
||||
logger.info("Running Tachidesk ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}")
|
||||
|
||||
// register Tachidesk's config which is dubbed "ServerConfig"
|
||||
GlobalConfigManager.registerModule(
|
||||
ServerConfig.register { GlobalConfigManager.config }
|
||||
@@ -68,6 +68,14 @@ fun applicationSetup() {
|
||||
// Application dirs
|
||||
val applicationDirs = ApplicationDirs()
|
||||
|
||||
initLoggerConfig(applicationDirs.dataRoot)
|
||||
|
||||
logger.info("Running Tachidesk ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}")
|
||||
|
||||
logger.debug {
|
||||
"Loaded config:\n" + GlobalConfigManager.config.root().render(ConfigRenderOptions.concise().setFormatted(true))
|
||||
}
|
||||
|
||||
val updater = Updater()
|
||||
|
||||
DI.global.addImport(
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="Exposed" level="ERROR"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user