This commit is contained in:
Horis 2024-03-02 18:10:06 +08:00
parent 483ed9455a
commit 6b5c32a3db
5 changed files with 34 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import android.content.res.Configuration
import android.os.Build
import com.github.liuyueyi.quick.transfer.constants.TransType
import com.jeremyliao.liveeventbus.LiveEventBus
import com.jeremyliao.liveeventbus.logger.DefaultLogger
import io.legado.app.base.AppContextWrapper
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
@ -40,6 +41,7 @@ import splitties.init.appCtx
import splitties.systemservices.notificationManager
import java.net.URL
import java.util.concurrent.TimeUnit
import java.util.logging.Level
class App : Application() {
@ -57,6 +59,7 @@ class App : Application() {
.lifecycleObserverAlwaysActive(true)
.autoClear(false)
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
.setLogger(EventLogger())
applyDayNight(this)
registerActivityLifecycleCallbacks(LifecycleHelp)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
@ -178,4 +181,21 @@ class App : Application() {
)
}
class EventLogger : DefaultLogger() {
override fun log(level: Level, msg: String) {
super.log(level, msg)
LogUtils.d(TAG, msg)
}
override fun log(level: Level, msg: String, th: Throwable?) {
super.log(level, msg, th)
LogUtils.d(TAG, "$msg\n${th?.stackTraceToString()}")
}
companion object {
private const val TAG = "[LiveEventBus]"
}
}
}

View File

@ -38,7 +38,9 @@ abstract class BaseService : LifecycleService() {
@CallSuper
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
LogUtils.d(simpleName, "onStartCommand $intent")
LogUtils.d(simpleName) {
"onStartCommand $intent ${intent?.toUri(0)}"
}
startForegroundNotification()
return super.onStartCommand(intent, flags, startId)
}

View File

@ -342,7 +342,8 @@ object ReadBook : CoroutineScope by MainScope() {
* 朗读
*/
fun readAloud(play: Boolean = true, startPos: Int = 0) {
book?.let {
book ?: return
if (isLayoutAvailable) {
ReadAloud.play(appCtx, play, startPos = startPos)
}
}

View File

@ -188,9 +188,9 @@ data class TextChapter(
pageSplit: Boolean,
): Int {
val paragraphs = if (pageSplit) {
pageParagraphs
if (isCompleted) pageParagraphs else pageParagraphsInternal
} else {
paragraphs
if (isCompleted) paragraphs else pageParagraphsInternal
}
paragraphs.forEach { paragraph ->
if (position in paragraph.chapterIndices) {

View File

@ -25,12 +25,18 @@ object LogUtils {
logger.log(Level.INFO, "$tag $msg")
}
inline fun d(tag: String, lazyMsg: () -> String) {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "$tag ${lazyMsg()}")
}
}
@JvmStatic
fun e(tag: String, msg: String) {
logger.log(Level.WARNING, "$tag $msg")
}
private val logger: Logger by lazy {
val logger: Logger by lazy {
Logger.getGlobal().apply {
fileHandler?.let {
addHandler(it)