@@ -32,42 +32,51 @@ fun logException(err: Throwable?) {
32
32
MiraiAndroidLogger .error(stringWriter.toString())
33
33
}
34
34
35
- internal fun processHTMLLog (log : String ): String =
36
- log.replace(" \n " , " <br>" )
37
- .replace(" <" , " <" )
38
- .replace(" >" , " >" )
39
- .replace(" &" , " &" )
40
- .replace(" \" " , " "" )
35
+ private val lock = Object ()
36
+
37
+ internal fun pushLog (log : String ) {
38
+ synchronized(lock) {
39
+ logStorage.add(log)
40
+ for (i in 0 until BotService .consoleUi.beginBroadcast()) {
41
+ try {
42
+ BotService .consoleUi.getBroadcastItem(i).newLog(log)
43
+ } catch (remoteE: Exception ) {
44
+ Log .e(" MA" , remoteE.message ? : " 发生错误" )
45
+ remoteE.printStackTrace()
46
+ logException(remoteE)
47
+ }
48
+ }
49
+ BotService .consoleUi.finishBroadcast()
50
+
51
+ }
52
+ }
53
+
41
54
42
55
object MiraiAndroidLogger :
43
56
SimpleLogger (LOGGER_IDENTITY , { priority: LogPriority , message: String? , e: Throwable ? ->
44
- val log = " [${priority.name} ] ${message ? : e} "
45
- val colorLog =
46
- " <font color=\" ${LogColor .valueOf(priority.name).color} \" >[${priority.name} ]</font> ${
47
- processHTMLLog(message ? : " " )
48
- } "
49
-
57
+ e?.printStackTrace()
58
+ logException(e)
50
59
synchronized(this ) {
51
- logStorage.add(colorLog)
52
- logException(e)
53
- for (i in 0 until BotService .consoleUi.beginBroadcast()) {
54
- try {
55
- BotService .consoleUi.getBroadcastItem(i).newLog(colorLog)
56
- } catch (remoteE: Exception ) {
57
- Log .e(" MA" , remoteE.message ? : " 发生错误" )
58
- remoteE.printStackTrace()
59
- logException(remoteE)
60
+ message?.split(" \n " )?.forEach {
61
+ val log = " [${priority.name} ] ${it} "
62
+ val colorLog =
63
+ " <font color=\" ${LogColor .valueOf(priority.name).color} \" >[${priority.name} ]</font><![CDATA[${
64
+ it.replace(
65
+ " \n " ,
66
+ " \r "
67
+ )
68
+ } ]]>"
69
+ pushLog(colorLog)
70
+
71
+
72
+ if (BuildConfig .DEBUG || printToSysLog) {
73
+ Log .i(" MA" , log)
60
74
}
61
75
}
62
- BotService .consoleUi.finishBroadcast()
63
76
}
77
+ }
64
78
65
- if (BuildConfig .DEBUG || printToSysLog) {
66
- Log .i(" MA" , log)
67
- e?.printStackTrace()
68
-
69
- }
70
- }) {
79
+ ) {
71
80
val logs: MutableList <String >
72
81
get() = logStorage.toMutableList()
73
82
0 commit comments