Use StorageManager for Exh logs
This commit is contained in:
parent
44fb882654
commit
7e6d1196ac
@ -8,7 +8,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
@ -68,13 +67,14 @@ import logcat.LogPriority
|
|||||||
import logcat.LogcatLogger
|
import logcat.LogcatLogger
|
||||||
import org.conscrypt.Conscrypt
|
import org.conscrypt.Conscrypt
|
||||||
import tachiyomi.core.i18n.stringResource
|
import tachiyomi.core.i18n.stringResource
|
||||||
|
import tachiyomi.core.storage.toFile
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
|
import tachiyomi.domain.storage.service.StorageManager
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.widget.WidgetManager
|
import tachiyomi.presentation.widget.WidgetManager
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.File
|
|
||||||
import java.security.Security
|
import java.security.Security
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -91,8 +91,6 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super<Application>.onCreate()
|
super<Application>.onCreate()
|
||||||
// if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
// if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
||||||
setupExhLogging() // EXH logging
|
|
||||||
LogcatLogger.install(XLogLogcatLogger()) // SY Redirect Logcat to XLog
|
|
||||||
|
|
||||||
GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java)
|
GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java)
|
||||||
|
|
||||||
@ -115,6 +113,9 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
Injekt.importModule(SYDomainModule())
|
Injekt.importModule(SYDomainModule())
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
|
setupExhLogging() // EXH logging
|
||||||
|
LogcatLogger.install(XLogLogcatLogger()) // SY Redirect Logcat to XLog
|
||||||
|
|
||||||
setupNotificationChannels()
|
setupNotificationChannels()
|
||||||
|
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||||
@ -248,30 +249,30 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
|
|
||||||
val printers = mutableListOf<Printer>(AndroidPrinter())
|
val printers = mutableListOf<Printer>(AndroidPrinter())
|
||||||
|
|
||||||
val logFolder = File(
|
val logFolder = Injekt.get<StorageManager>().getLogsDirectory()
|
||||||
Environment.getExternalStorageDirectory().absolutePath + File.separator +
|
?.toFile()
|
||||||
stringResource(MR.strings.app_name),
|
?.absolutePath
|
||||||
"logs",
|
|
||||||
)
|
|
||||||
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
|
if (logFolder != null) {
|
||||||
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
|
||||||
|
|
||||||
printers += EnhancedFilePrinter
|
printers += EnhancedFilePrinter
|
||||||
.Builder(logFolder.absolutePath) {
|
.Builder(logFolder) {
|
||||||
fileNameGenerator = object : DateFileNameGenerator() {
|
fileNameGenerator = object : DateFileNameGenerator() {
|
||||||
override fun generateFileName(logLevel: Int, timestamp: Long): String {
|
override fun generateFileName(logLevel: Int, timestamp: Long): String {
|
||||||
return super.generateFileName(
|
return super.generateFileName(
|
||||||
logLevel,
|
logLevel,
|
||||||
timestamp,
|
timestamp,
|
||||||
) + "-${BuildConfig.BUILD_TYPE}.log"
|
) + "-${BuildConfig.BUILD_TYPE}.log"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
flattener { timeMillis, level, tag, message ->
|
||||||
|
"${dateFormat.format(timeMillis)} ${LogLevel.getShortLevelName(level)}/$tag: $message"
|
||||||
|
}
|
||||||
|
cleanStrategy = FileLastModifiedCleanStrategy(7.days.inWholeMilliseconds)
|
||||||
|
backupStrategy = NeverBackupStrategy()
|
||||||
}
|
}
|
||||||
flattener { timeMillis, level, tag, message ->
|
}
|
||||||
"${dateFormat.format(timeMillis)} ${LogLevel.getShortLevelName(level)}/$tag: $message"
|
|
||||||
}
|
|
||||||
cleanStrategy = FileLastModifiedCleanStrategy(7.days.inWholeMilliseconds)
|
|
||||||
backupStrategy = NeverBackupStrategy()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Install Crashlytics in prod
|
// Install Crashlytics in prod
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
|
@ -47,8 +47,17 @@ class StorageManager(
|
|||||||
fun getLocalSourceDirectory(): UniFile? {
|
fun getLocalSourceDirectory(): UniFile? {
|
||||||
return baseDir?.createDirectory(LOCAL_SOURCE_PATH)
|
return baseDir?.createDirectory(LOCAL_SOURCE_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SY -->
|
||||||
|
fun getLogsDirectory(): UniFile? {
|
||||||
|
return baseDir?.createDirectory(LOGS_PATH)
|
||||||
|
}
|
||||||
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val AUTOMATIC_BACKUPS_PATH = "autobackup"
|
private const val AUTOMATIC_BACKUPS_PATH = "autobackup"
|
||||||
private const val DOWNLOADS_PATH = "downloads"
|
private const val DOWNLOADS_PATH = "downloads"
|
||||||
private const val LOCAL_SOURCE_PATH = "local"
|
private const val LOCAL_SOURCE_PATH = "local"
|
||||||
|
// SY -->
|
||||||
|
private const val LOGS_PATH = "logs"
|
||||||
|
// SY <--
|
||||||
|
Loading…
x
Reference in New Issue
Block a user