From 2d18ab82054f1470384bcdedc0b1beb9a61c2dfa Mon Sep 17 00:00:00 2001 From: ryoii Date: Sun, 29 Mar 2020 20:40:07 +0800 Subject: [PATCH 1/2] Timestamp for log --- .../controller/MiraiGraphicalUIController.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt index c7cd8d082..b3d6e34ab 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt @@ -17,6 +17,8 @@ import net.mamoe.mirai.network.WrongPasswordException import net.mamoe.mirai.utils.LoginSolver import net.mamoe.mirai.utils.SimpleLogger.LogPriority import tornadofx.* +import java.text.SimpleDateFormat +import java.util.* class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { @@ -31,6 +33,10 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { val consoleInfo = ConsoleInfo() + val sdf by lazy { + SimpleDateFormat("HH:mm:ss") + } + fun login(qq: String, psd: String) { CommandManager.runCommand(ConsoleCommandSender, "/login $qq $psd") } @@ -50,13 +56,16 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { } Platform.runLater { + + val time = sdf.format(Date()) + when (identity) { 0L -> mainLog.apply { - add("$identityStr $message") + add("[$time] $identityStr $message") trim() } else -> cache[identity]?.logHistory?.apply { - add("$identityStr $message") + add("[$time] $identityStr $message") trim() } } From f72d598f6625444ab55d7c5d4f3fe0bb7af6bac2 Mon Sep 17 00:00:00 2001 From: ryoii Date: Sun, 29 Mar 2020 23:13:08 +0800 Subject: [PATCH 2/2] Log error --- .../controller/MiraiGraphicalUIController.kt | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt index b3d6e34ab..dcef0c963 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt @@ -49,25 +49,17 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { // 修改interface之后用来暂时占位 override fun pushLog(priority: LogPriority, identityStr: String, identity: Long, message: String) { - fun ObservableList<*>.trim() { - if (size > settingModel.item.maxLongNum) { - this.removeAt(0) - } - } - Platform.runLater { val time = sdf.format(Date()) - when (identity) { - 0L -> mainLog.apply { - add("[$time] $identityStr $message") - trim() - } - else -> cache[identity]?.logHistory?.apply { - add("[$time] $identityStr $message") - trim() - } + if (identity == 0L) { + mainLog + } else { + cache[identity]?.logHistory + }?.apply { + add("[$time] $identityStr $message") + trim() } } } @@ -98,7 +90,9 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { Platform.runLater { ret = InputDialog(hint).open() } - while (ret == null) { delay(1000) } + while (ret == null) { + delay(1000) + } return ret!! } @@ -111,6 +105,15 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { private fun getPluginsFromConsole(): ObservableList = PluginManager.getAllPluginDescriptions().map(::PluginModel).toObservable() + + private fun ObservableList<*>.trim() { + println(size) + println(settingModel.item.maxLongNum) + while (size > settingModel.item.maxLongNum) { + this.removeAt(0) + } + } + } class GraphicalLoginSolver : LoginSolver() {