|
@@ -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,28 +48,34 @@ object LogUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private val fileHandler by lazy {
|
|
private val fileHandler by lazy {
|
|
|
- val root = appCtx.externalCacheDir ?: return@lazy null
|
|
|
|
|
- val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
|
|
|
|
- val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
|
|
|
|
- logFolder.listFiles()?.forEach {
|
|
|
|
|
- if (it.lastModified() < expiredTime) {
|
|
|
|
|
- it.delete()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- val date = getCurrentDateStr(TIME_PATTERN)
|
|
|
|
|
- val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
|
|
|
|
|
- AsyncFileHandler(logPath).apply {
|
|
|
|
|
- formatter = object : java.util.logging.Formatter() {
|
|
|
|
|
- override fun format(record: LogRecord): String {
|
|
|
|
|
- // 设置文件输出格式
|
|
|
|
|
- return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n")
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ val root = appCtx.externalCacheDir ?: return@lazy null
|
|
|
|
|
+ val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
|
|
|
|
+ val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
|
|
|
|
+ logFolder.listFiles()?.forEach {
|
|
|
|
|
+ if (it.lastModified() < expiredTime) {
|
|
|
|
|
+ it.delete()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- level = if (AppConfig.recordLog) {
|
|
|
|
|
- Level.INFO
|
|
|
|
|
- } else {
|
|
|
|
|
- Level.OFF
|
|
|
|
|
|
|
+ val date = getCurrentDateStr(TIME_PATTERN)
|
|
|
|
|
+ val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
|
|
|
|
|
+ AsyncFileHandler(logPath).apply {
|
|
|
|
|
+ formatter = object : java.util.logging.Formatter() {
|
|
|
|
|
+ override fun format(record: LogRecord): String {
|
|
|
|
|
+ // 设置文件输出格式
|
|
|
|
|
+ return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ level = if (AppConfig.recordLog) {
|
|
|
|
|
+ Level.INFO
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Level.OFF
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (e: Exception) {
|
|
|
|
|
+ e.printStackTrace()
|
|
|
|
|
+ AppLog.putNotSave("创建fileHandler出错\n$e", e)
|
|
|
|
|
+ return@lazy null
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|