1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 20:12:39 +01:00

Remove pref component from logger

This commit is contained in:
Allan Wang 2020-02-23 16:47:57 -08:00
parent 0dfc1b3e65
commit 44de8239ec
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
3 changed files with 26 additions and 23 deletions

View File

@ -19,6 +19,7 @@ package com.pitchedapps.frost
import android.app.Activity
import android.app.Application
import android.os.Bundle
import android.util.Log
import ca.allanwang.kau.kpref.KPrefFactory
import ca.allanwang.kau.kpref.KPrefFactoryAndroid
import ca.allanwang.kau.logging.KL
@ -34,7 +35,6 @@ import com.pitchedapps.frost.utils.FrostPglAdBlock
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.Showcase
import java.util.Random
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.KoinComponent
@ -42,6 +42,7 @@ import org.koin.core.context.startKoin
import org.koin.core.get
import org.koin.core.module.Module
import org.koin.dsl.module
import java.util.Random
/**
* Created by Allan Wang on 2017-05-28.
@ -57,13 +58,15 @@ class FrostApp : Application(), KoinComponent {
androidLogger()
}
androidContext(this@FrostApp)
modules(listOf(
modules(
listOf(
FrostDatabase.module(),
prefFactoryModule(),
Prefs.module(),
Showcase.module(),
FbCookie.module()
))
)
)
}
if (!buildIsLollipopAndUp) { // not supported
super.onCreate()
@ -108,6 +111,13 @@ class FrostApp : Application(), KoinComponent {
prefs.deleteKeys("search_bar")
showcasePrefs.deleteKeys("shown_release", "experimental_by_default")
KL.shouldLog = { BuildConfig.DEBUG }
L.shouldLog = {
when (it) {
Log.VERBOSE -> BuildConfig.DEBUG
Log.INFO, Log.ERROR -> true
else -> BuildConfig.DEBUG || prefs.verboseLogging
}
}
prefs.verboseLogging = false
if (prefs.installDate == -1L) {
prefs.installDate = System.currentTimeMillis()
@ -135,7 +145,7 @@ class FrostApp : Application(), KoinComponent {
enableExceptionHandler = prefs.analytics
}
Bugsnag.init(this, config)
L.bugsnagInit = true
L.hasAnalytics = { prefs.analytics }
Bugsnag.setUserId(prefs.frostId)
Bugsnag.addToTab("Build", "Application", BuildConfig.APPLICATION_ID)
Bugsnag.addToTab("Build", "Version", BuildConfig.VERSION_NAME)

View File

@ -16,28 +16,17 @@
*/
package com.pitchedapps.frost.utils
import android.util.Log
import ca.allanwang.kau.logging.KauLogger
import ca.allanwang.kau.logging.KauLoggerExtension
import com.bugsnag.android.Bugsnag
import com.pitchedapps.frost.BuildConfig
import org.koin.core.KoinComponent
import org.koin.core.inject
/**
* Created by Allan Wang on 2017-05-28.
*
* Logging for frost
*/
object L : KauLogger("Frost", {
when (it) {
Log.VERBOSE -> BuildConfig.DEBUG
Log.INFO, Log.ERROR -> true
else -> BuildConfig.DEBUG || L.prefs.verboseLogging
}
}), KoinComponent {
private val prefs: Prefs by inject()
object L : KauLogger("Frost") {
inline fun test(message: () -> Any?) {
_d {
@ -63,7 +52,7 @@ object L : KauLogger("Frost", {
}
}
var bugsnagInit = false
var hasAnalytics: () -> Boolean = { false }
override fun logImpl(priority: Int, message: String?, t: Throwable?) {
/*
@ -71,7 +60,7 @@ object L : KauLogger("Frost", {
* bugsnagInit is changed per application and helps prevent crashes (if calling pre init)
* analytics is changed by the user, and may be toggled throughout the app
*/
if (BuildConfig.DEBUG || !bugsnagInit || !prefs.analytics) {
if (BuildConfig.DEBUG || !hasAnalytics()) {
super.logImpl(priority, message, t)
} else {
if (message != null) {

View File

@ -158,6 +158,10 @@ class Prefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs"
var enablePip: Boolean by kpref("enable_pip", true)
/**
* Despite the naming, this toggle currently only enables debug logging.
* Verbose is never logged in release builds.
*/
var verboseLogging: Boolean by kpref("verbose_logging", false)
var analytics: Boolean by kpref("analytics", false) {