mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Don't log everything to log files unless verbose logging is enabled
This commit is contained in:
parent
acafe931f1
commit
e65497baef
2 changed files with 19 additions and 9 deletions
|
@ -22,6 +22,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.multidex.MultiDex
|
import androidx.multidex.MultiDex
|
||||||
|
import co.touchlab.kermit.LogWriter
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import coil3.PlatformContext
|
import coil3.PlatformContext
|
||||||
|
@ -113,7 +114,12 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
|
|
||||||
val scope = ProcessLifecycleOwner.get().lifecycleScope
|
val scope = ProcessLifecycleOwner.get().lifecycleScope
|
||||||
|
|
||||||
Logger.setToDefault(buildLogWritersToAdd(storageManager.getLogsDirectory()))
|
networkPreferences.verboseLogging().changes()
|
||||||
|
.onEach { enabled ->
|
||||||
|
// FlexibleAdapter.enableLogs(if (enabled) Level.VERBOSE else Level.SUPPRESS)
|
||||||
|
Logger.setToDefault(buildLogWritersToAdd(storageManager.getLogsDirectory(), enabled))
|
||||||
|
}
|
||||||
|
.launchIn(scope)
|
||||||
|
|
||||||
basePreferences.crashReport().changes()
|
basePreferences.crashReport().changes()
|
||||||
.onEach {
|
.onEach {
|
||||||
|
@ -139,12 +145,6 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
.onEach { ImageUtil.hardwareBitmapThreshold = it }
|
.onEach { ImageUtil.hardwareBitmapThreshold = it }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
// networkPreferences.verboseLogging().changes()
|
|
||||||
// .onEach { enabled ->
|
|
||||||
// FlexibleAdapter.enableLogs(if (enabled) Level.VERBOSE else Level.SUPPRESS)
|
|
||||||
// }
|
|
||||||
// .launchIn(scope)
|
|
||||||
|
|
||||||
scope.launchIO {
|
scope.launchIO {
|
||||||
with(TachiyomiWidgetManager()) { this@App.init() }
|
with(TachiyomiWidgetManager()) { this@App.init() }
|
||||||
}
|
}
|
||||||
|
@ -289,12 +289,18 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun buildLogWritersToAdd(logPath: UniFile?): List<LogWriter> {
|
||||||
|
val networkPreferences: NetworkPreferences = Injekt.get()
|
||||||
|
return buildLogWritersToAdd(logPath, networkPreferences.verboseLogging().get())
|
||||||
|
}
|
||||||
|
|
||||||
fun buildLogWritersToAdd(
|
fun buildLogWritersToAdd(
|
||||||
logPath: UniFile?,
|
logPath: UniFile?,
|
||||||
|
isVerbose: Boolean,
|
||||||
) = buildList {
|
) = buildList {
|
||||||
if (!BuildConfig.DEBUG) add(CrashlyticsLogWriter())
|
if (!BuildConfig.DEBUG) add(CrashlyticsLogWriter())
|
||||||
|
|
||||||
if (logPath != null) add(RollingUniFileLogWriter(logPath))
|
if (logPath != null) add(RollingUniFileLogWriter(logPath = logPath, isVerbose = isVerbose))
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val ACTION_DISABLE_INCOGNITO_MODE = "tachi.action.DISABLE_INCOGNITO_MODE"
|
private const val ACTION_DISABLE_INCOGNITO_MODE = "tachi.action.DISABLE_INCOGNITO_MODE"
|
||||||
|
|
|
@ -43,7 +43,8 @@ class RollingUniFileLogWriter(
|
||||||
private val maxRolledLogFiles: Int = 5,
|
private val maxRolledLogFiles: Int = 5,
|
||||||
private val maxLogFiles: Int = 5,
|
private val maxLogFiles: Int = 5,
|
||||||
private val messageStringFormatter: MessageStringFormatter = DefaultFormatter,
|
private val messageStringFormatter: MessageStringFormatter = DefaultFormatter,
|
||||||
private val messageDateFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
|
private val messageDateFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault()),
|
||||||
|
private val isVerbose: Boolean = false,
|
||||||
) : LogWriter() {
|
) : LogWriter() {
|
||||||
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
|
||||||
private val coroutineScope = CoroutineScope(
|
private val coroutineScope = CoroutineScope(
|
||||||
|
@ -64,6 +65,9 @@ class RollingUniFileLogWriter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isLoggable(tag: String, severity: Severity): Boolean =
|
||||||
|
severity >= if (isVerbose) Severity.Debug else Severity.Info
|
||||||
|
|
||||||
override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
|
override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
|
||||||
bufferLog(
|
bufferLog(
|
||||||
formatMessage(
|
formatMessage(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue