Skip to content

Commit beb561a

Browse files
committed
优化
1 parent 452925f commit beb561a

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.legado.app.utils
2+
3+
import io.legado.app.help.globalExecutor
4+
import java.util.logging.FileHandler
5+
import java.util.logging.LogRecord
6+
7+
class AsyncFileHandler(pattern: String) : FileHandler(pattern) {
8+
9+
override fun publish(record: LogRecord?) {
10+
if (!isLoggable(record)) {
11+
return
12+
}
13+
globalExecutor.execute {
14+
super.publish(record)
15+
}
16+
}
17+
18+
}

app/src/main/java/io/legado/app/utils/AsyncHandler.kt

-25
This file was deleted.

app/src/main/java/io/legado/app/utils/LogUtils.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import io.legado.app.help.config.AppConfig
1111
import splitties.init.appCtx
1212
import java.text.SimpleDateFormat
1313
import java.util.Date
14-
import java.util.logging.FileHandler
1514
import java.util.logging.Level
1615
import java.util.logging.LogRecord
1716
import java.util.logging.Logger
@@ -58,7 +57,7 @@ object LogUtils {
5857
}
5958
val date = getCurrentDateStr(TIME_PATTERN)
6059
val logPath = FileUtils.getPath(root = logFolder, "appLog-$date.txt")
61-
FileHandler(logPath).apply {
60+
AsyncFileHandler(logPath).apply {
6261
formatter = object : java.util.logging.Formatter() {
6362
override fun format(record: LogRecord): String {
6463
// 设置文件输出格式
@@ -70,7 +69,7 @@ object LogUtils {
7069
} else {
7170
Level.OFF
7271
}
73-
}.asynchronous()
72+
}
7473
}
7574

7675
fun upLevel() {

0 commit comments

Comments
 (0)