Cleanup Log usage and make logging configurable

This commit is contained in:
FooIbar committed 2024-02-13 00:23:10 +08:00
1 parent a9dd705ec5
commit 5fe520e575
6 files changed
+23 -24

No files matched your search

@@ -89,6 +89,9 @@ class EhApplication : Application(), SingletonImageLoader.Factory {
AppCompatDelegate.setDefaultNightMode(mode)
}
}
if (!LogcatLogger.isInstalled && Settings.saveCrashLog) {
LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE))
}
}
lifecycle.addObserver(lockObserver)
val handler = Thread.getDefaultUncaughtExceptionHandler()
@@ -105,7 +108,6 @@ class EhApplication : Application(), SingletonImageLoader.Factory {
System.loadLibrary("ehviewer")
System.loadLibrary("ehviewer_rust")
ReadableTime.initialize(this)
LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE))
lifecycleScope.launchIO {
launchIO {
EhTagDatabase
@@ -15,14 +15,13 @@
*/
package com.hippo.ehviewer.client.parser
import android.util.Log
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.exception.ParseException
import com.hippo.ehviewer.util.ExceptionUtils
import eu.kanade.tachiyomi.util.system.logcat
import org.jsoup.Jsoup
object ProfileParser {
private val TAG = ProfileParser::class.java.simpleName
fun parse(body: String): Result {
return runCatching {
val d = Jsoup.parse(body)
@@ -40,7 +39,7 @@ object ProfileParser {
}
}.getOrElse {
ExceptionUtils.throwIfFatal(it)
Log.i(TAG, "No avatar")
logcat { "No avatar" }
null
}
Result(displayName, avatar)
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.download
import android.net.Uri
import android.util.Log
import android.util.SparseLongArray
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisallowComposableCalls
@@ -53,6 +52,7 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import logcat.LogPriority
import splitties.preferences.edit
object DownloadManager : OnSpiderListener {
@@ -200,7 +200,7 @@ object DownloadManager : OnSpiderListener {
// Add to label download list
val list = getInfoListForLabel(info.label)
if (list == null) {
Log.e(TAG, "Can't find download info list with label: $label")
logcat(TAG, LogPriority.ERROR) { "Can't find download info list with label: $label" }
return
}
list.add(0, info)
@@ -548,12 +548,12 @@ object DownloadManager : OnSpiderListener {
*/
suspend fun changeLabel(list: Collection<DownloadInfo>, label: String?) {
if (null != label && !containLabel(label)) {
Log.e(TAG, "Not exits label: $label")
logcat(TAG, LogPriority.ERROR) { "Not exits label: $label" }
return
}
val dstList = getInfoListForLabel(label)
if (dstList == null) {
Log.e(TAG, "Can't find label with label: $label")
logcat(TAG, LogPriority.ERROR) { "Can't find label with label: $label" }
return
}
for (info in list) {
@@ -562,7 +562,7 @@ object DownloadManager : OnSpiderListener {
}
val srcList = getInfoListForLabel(info.label)
if (srcList == null) {
Log.e(TAG, "Can't find label with label: " + info.label)
logcat(TAG, LogPriority.ERROR) { "Can't find label with label: " + info.label }
continue
}
srcList.remove(info)
@@ -800,7 +800,7 @@ object DownloadManager : OnSpiderListener {
TYPE_ON_GET_PAGES -> {
val info = mCurrentTask
if (info == null) {
Log.e(TAG, "Current task is null, but it should not be")
logcat(TAG, LogPriority.ERROR) { "Current task is null, but it should not be" }
} else {
info.total = mPages
launchIO {
@@ -826,7 +826,7 @@ object DownloadManager : OnSpiderListener {
mSpeedReminder.onDone(mIndex)
val info = mCurrentTask
if (info == null) {
Log.e(TAG, "Current task is null, but it should not be")
logcat(TAG, LogPriority.ERROR) { "Current task is null, but it should not be" }
} else {
info.finished = mFinished
info.downloaded = mDownloaded
@@ -844,7 +844,7 @@ object DownloadManager : OnSpiderListener {
mSpeedReminder.onDone(mIndex)
val info = mCurrentTask
if (info == null) {
Log.e(TAG, "Current task is null, but it should not be")
logcat(TAG, LogPriority.ERROR) { "Current task is null, but it should not be" }
} else {
info.finished = mFinished
info.downloaded = mDownloaded
@@ -869,7 +869,7 @@ object DownloadManager : OnSpiderListener {
}
// Check null
if (info == null || spider == null) {
Log.e(TAG, "Current stuff is null, but it should not be")
logcat(TAG, LogPriority.ERROR) { "Current stuff is null, but it should not be" }
} else {
// Stop speed count
mSpeedReminder.stop()
@@ -22,7 +22,6 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.SystemClock
import android.util.Log
import androidx.annotation.IntDef
import androidx.collection.LongSparseArray
import androidx.core.app.ActivityCompat
@@ -40,6 +39,7 @@ import com.hippo.ehviewer.util.FileUtils
import com.hippo.ehviewer.util.ReadableTime
import com.hippo.ehviewer.util.SimpleHandler
import com.hippo.ehviewer.util.getParcelableExtraCompat
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -339,7 +339,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener, CoroutineSc
sItemTitleArray.valueAt(0),
)
} else {
Log.d("TAG", "WTF, sItemTitleArray is null")
logcat { "WTF, sItemTitleArray is null" }
getString(R.string.error_unknown)
}
needStyle = false
@@ -355,7 +355,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener, CoroutineSc
sItemTitleArray.valueAt(0),
)
} else {
Log.d("TAG", "WTF, sItemTitleArray is null")
logcat { "WTF, sItemTitleArray is null" }
getString(R.string.error_unknown)
}
needStyle = false
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.gallery
import android.os.ParcelFileDescriptor
import android.util.Log
import com.hippo.ehviewer.Settings.archivePasswds
import com.hippo.ehviewer.image.ByteBufferSource
import com.hippo.ehviewer.image.Image
@@ -54,7 +53,7 @@ class ArchivePageLoader(
) : PageLoader2(gid, startPage) {
private lateinit var pfd: ParcelFileDescriptor
private val hostJob = launch(start = CoroutineStart.LAZY) {
Log.d(DEBUG_TAG, "Open archive ${file.uri.displayPath}")
logcat(DEBUG_TAG) { "Open archive ${file.uri.displayPath}" }
pfd = file.openFileDescriptor("r")
size = openArchive(pfd.fd, pfd.statSize)
if (size == 0) {
@@ -82,7 +81,7 @@ class ArchivePageLoader(
super.stop()
closeArchive()
pfd.close()
Log.d(DEBUG_TAG, "Close archive ${file.uri.displayPath} successfully!")
logcat(DEBUG_TAG) { "Close archive ${file.uri.displayPath} successfully!" }
}
private val mJobMap = hashMapOf<Int, Job>()
@@ -16,7 +16,6 @@
*/
package com.hippo.ehviewer.spider
import android.util.Log
import androidx.annotation.IntDef
import androidx.collection.LongSparseArray
import androidx.collection.set
@@ -551,7 +550,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}.onFailure {
if (it is CancellationException) {
if (mReadReference > 0) {
Log.d(WORKER_DEBUG_TAG, "Download image $index cancelled")
logcat(WORKER_DEBUG_TAG) { "Download image $index cancelled" }
if (it.message != FORCE_RETRY) {
updatePageState(index, STATE_FAILED, "Cancelled")
}
@@ -677,7 +676,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
repeat(2) { times ->
runCatching {
Log.d(WORKER_DEBUG_TAG, "Start download image $index attempt #$times")
logcat(WORKER_DEBUG_TAG) { "Start download image $index attempt #$times" }
val success = withTimeout(downloadTimeout) {
mSpiderDen.makeHttpCallAndSaveImage(
index,
@@ -688,12 +687,12 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}
check(success)
Log.d(WORKER_DEBUG_TAG, "Download image $index succeed")
logcat(WORKER_DEBUG_TAG) { "Download image $index succeed" }
updatePageState(index, STATE_FINISHED)
return
}.onFailure {
mSpiderDen.remove(index)
Log.d(WORKER_DEBUG_TAG, "Download image $index attempt #$times failed")
logcat(WORKER_DEBUG_TAG) { "Download image $index attempt #$times failed" }
error = when (it) {
is TimeoutCancellationException -> ERROR_TIMEOUT
is CancellationException -> throw it