mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
18
app/src/main/java/io/legado/app/utils/AsyncFileHandler.kt
Normal file
18
app/src/main/java/io/legado/app/utils/AsyncFileHandler.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import io.legado.app.help.globalExecutor
|
||||
import java.util.logging.FileHandler
|
||||
import java.util.logging.LogRecord
|
||||
|
||||
class AsyncFileHandler(pattern: String) : FileHandler(pattern) {
|
||||
|
||||
override fun publish(record: LogRecord?) {
|
||||
if (!isLoggable(record)) {
|
||||
return
|
||||
}
|
||||
globalExecutor.execute {
|
||||
super.publish(record)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import io.legado.app.help.globalExecutor
|
||||
import java.util.logging.Handler
|
||||
import java.util.logging.LogRecord
|
||||
|
||||
class AsyncHandler(private val delegate: Handler) : Handler() {
|
||||
|
||||
override fun publish(record: LogRecord?) {
|
||||
globalExecutor.execute {
|
||||
delegate.publish(record)
|
||||
}
|
||||
}
|
||||
|
||||
override fun flush() {
|
||||
delegate.flush()
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
delegate.close()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun Handler.asynchronous() = AsyncHandler(this)
|
||||
@@ -11,7 +11,6 @@ import io.legado.app.help.config.AppConfig
|
||||
import splitties.init.appCtx
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.logging.FileHandler
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.LogRecord
|
||||
import java.util.logging.Logger
|
||||
@@ -58,7 +57,7 @@ object LogUtils {
|
||||
}
|
||||
val date = getCurrentDateStr(TIME_PATTERN)
|
||||
val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
|
||||
FileHandler(logPath).apply {
|
||||
AsyncFileHandler(logPath).apply {
|
||||
formatter = object : java.util.logging.Formatter() {
|
||||
override fun format(record: LogRecord): String {
|
||||
// 设置文件输出格式
|
||||
@@ -70,7 +69,7 @@ object LogUtils {
|
||||
} else {
|
||||
Level.OFF
|
||||
}
|
||||
}.asynchronous()
|
||||
}
|
||||
}
|
||||
|
||||
fun upLevel() {
|
||||
|
||||
Reference in New Issue
Block a user