优化
This commit is contained in:
@@ -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 splitties.init.appCtx
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.logging.FileHandler
|
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import java.util.logging.LogRecord
|
import java.util.logging.LogRecord
|
||||||
import java.util.logging.Logger
|
import java.util.logging.Logger
|
||||||
@@ -58,7 +57,7 @@ object LogUtils {
|
|||||||
}
|
}
|
||||||
val date = getCurrentDateStr(TIME_PATTERN)
|
val date = getCurrentDateStr(TIME_PATTERN)
|
||||||
val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
|
val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
|
||||||
FileHandler(logPath).apply {
|
AsyncFileHandler(logPath).apply {
|
||||||
formatter = object : java.util.logging.Formatter() {
|
formatter = object : java.util.logging.Formatter() {
|
||||||
override fun format(record: LogRecord): String {
|
override fun format(record: LogRecord): String {
|
||||||
// 设置文件输出格式
|
// 设置文件输出格式
|
||||||
@@ -70,7 +69,7 @@ object LogUtils {
|
|||||||
} else {
|
} else {
|
||||||
Level.OFF
|
Level.OFF
|
||||||
}
|
}
|
||||||
}.asynchronous()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upLevel() {
|
fun upLevel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user