package io.legato.kazusa.constant import android.util.Log import io.legato.kazusa.BuildConfig import io.legato.kazusa.help.config.AppConfig import io.legato.kazusa.utils.LogUtils import io.legato.kazusa.utils.toastOnUi import splitties.init.appCtx object AppLog { private val mLogs = arrayListOf>() val logs get() = mLogs.toList() @Synchronized fun put(message: String?, throwable: Throwable? = null, toast: Boolean = false) { message ?: return if (toast) { appCtx.toastOnUi(message) } if (mLogs.size > 100) { mLogs.removeLastOrNull() } if (throwable == null) { LogUtils.d("AppLog", message) } else { LogUtils.d("AppLog", "$message\n${throwable.stackTraceToString()}") } mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable)) if (BuildConfig.DEBUG) { val stackTrace = Thread.currentThread().stackTrace Log.e(stackTrace[3].className, message, throwable) } } @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 fun clear() { mLogs.clear() } fun putDebug(message: String?, throwable: Throwable? = null) { if (AppConfig.recordLog) { put(message, throwable) } } }