|
|
|
@ -2,7 +2,6 @@ package io.legado.app.utils |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import java.io.File |
|
|
|
|
import java.text.SimpleDateFormat |
|
|
|
|
import java.util.* |
|
|
|
|
import java.util.logging.* |
|
|
|
@ -24,18 +23,17 @@ object LogUtils { |
|
|
|
|
|
|
|
|
|
private val logger: Logger by lazy { |
|
|
|
|
Logger.getGlobal().apply { |
|
|
|
|
addHandler(fileHandler) |
|
|
|
|
fileHandler?.let { |
|
|
|
|
addHandler(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val fileHandler by lazy { |
|
|
|
|
val logFolder = FileUtils.getCachePath() + File.separator + "logs" |
|
|
|
|
FileUtils.createFolderIfNotExist(logFolder) |
|
|
|
|
FileHandler( |
|
|
|
|
logFolder + File.separator + "app.log", |
|
|
|
|
10240, |
|
|
|
|
10 |
|
|
|
|
).apply { |
|
|
|
|
val root = App.INSTANCE.externalCacheDir ?: return@lazy null |
|
|
|
|
val logFolder = FileUtils.createFolderIfNotExist(root, "logs") |
|
|
|
|
val logPath = FileUtils.getPath(logFolder, "appLog") |
|
|
|
|
FileHandler(logPath, 10240, 10).apply { |
|
|
|
|
formatter = object : Formatter() { |
|
|
|
|
override fun format(record: LogRecord): String { |
|
|
|
|
// 设置文件输出格式 |
|
|
|
@ -51,7 +49,7 @@ object LogUtils { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun upLevel() { |
|
|
|
|
fileHandler.level = if (App.INSTANCE.getPrefBoolean("recordLog")) { |
|
|
|
|
fileHandler?.level = if (App.INSTANCE.getPrefBoolean("recordLog")) { |
|
|
|
|
Level.INFO |
|
|
|
|
} else { |
|
|
|
|
Level.OFF |
|
|
|
|