优化
This commit is contained in:
@@ -52,13 +52,13 @@ class App : Application() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
CrashHandler(this)
|
||||||
LogUtils.d("App", "onCreate")
|
LogUtils.d("App", "onCreate")
|
||||||
LogUtils.logDeviceInfo()
|
LogUtils.logDeviceInfo()
|
||||||
if (isDebuggable) {
|
if (isDebuggable) {
|
||||||
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
||||||
}
|
}
|
||||||
oldConfig = Configuration(resources.configuration)
|
oldConfig = Configuration(resources.configuration)
|
||||||
CrashHandler(this)
|
|
||||||
//预下载Cronet so
|
//预下载Cronet so
|
||||||
Cronet.preDownload()
|
Cronet.preDownload()
|
||||||
createNotificationChannels()
|
createNotificationChannels()
|
||||||
|
|||||||
@@ -34,6 +34,22 @@ object AppLog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun putNotSave(message: String?, throwable: Throwable? = null, toast: Boolean = false) {
|
||||||
|
message ?: return
|
||||||
|
if (toast) {
|
||||||
|
appCtx.toastOnUi(message)
|
||||||
|
}
|
||||||
|
if (mLogs.size > 100) {
|
||||||
|
mLogs.removeLastOrNull()
|
||||||
|
}
|
||||||
|
mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable))
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
val stackTrace = Thread.currentThread().stackTrace
|
||||||
|
Log.e(stackTrace[3].className, message, throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun clear() {
|
fun clear() {
|
||||||
mLogs.clear()
|
mLogs.clear()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.os.Build
|
|||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
import io.legado.app.BuildConfig
|
import io.legado.app.BuildConfig
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -47,6 +48,7 @@ object LogUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val fileHandler by lazy {
|
private val fileHandler by lazy {
|
||||||
|
try {
|
||||||
val root = appCtx.externalCacheDir ?: return@lazy null
|
val root = appCtx.externalCacheDir ?: return@lazy null
|
||||||
val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
||||||
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
||||||
@@ -70,6 +72,11 @@ object LogUtils {
|
|||||||
Level.OFF
|
Level.OFF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
AppLog.putNotSave("创建fileHandler出错\n$e", e)
|
||||||
|
return@lazy null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upLevel() {
|
fun upLevel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user