From 1afe0f07a8e6412cbf3c1a98183dcfb5a8f2c502 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 29 Jun 2022 03:03:16 +0800 Subject: [PATCH] =?UTF-8?q?perf(extension):=20=E4=BC=98=E5=8C=96=20printEx?= =?UTF-8?q?tensionFileConflictError=20=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kotlin-logging 在日志输出方法中做了检查, 如果级别未开启则不会调用方法获取日志内容, 故将内容构造部分移入 error 代码块以避免无意义的生成日志内容. --- .../src/main/kotlin/ExtensionComponents.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scalabot-app/src/main/kotlin/ExtensionComponents.kt b/scalabot-app/src/main/kotlin/ExtensionComponents.kt index 7b86e56..6c2baa5 100644 --- a/scalabot-app/src/main/kotlin/ExtensionComponents.kt +++ b/scalabot-app/src/main/kotlin/ExtensionComponents.kt @@ -145,22 +145,24 @@ internal class ExtensionLoader( extensionArtifact: Artifact, foundResult: Map> ) { - val errMessage = StringBuilder( - """ - [Bot ${bot.botUsername}] 扩展包 $extensionArtifact 存在多个文件, 为防止安全问题, 已禁止加载该扩展包: - """.trimIndent() - ).append('\n') + log.error { + val errMessage = StringBuilder( + """ + [Bot ${bot.botUsername}] 扩展包 $extensionArtifact 存在多个文件, 为防止安全问题, 已禁止加载该扩展包: + """.trimIndent() + ).append('\n') - foundResult.forEach { (finder, files) -> - errMessage.append("\t- 搜索器 `").append(finder::class.simpleName).append("`") - .append("(Priority: ${finder.getPriority()})") - .append(" 找到了以下扩展包: \n") - for (file in files) { - errMessage.append("\t\t* ") - .append(URLDecoder.decode(file.getRawUrl().toString(), StandardCharsets.UTF_8)).append('\n') + foundResult.forEach { (finder, files) -> + errMessage.append("\t- 搜索器 `").append(finder::class.simpleName).append("`") + .append("(Priority: ${finder.getPriority()})") + .append(" 找到了以下扩展包: \n") + for (file in files) { + errMessage.append("\t\t* ") + .append(URLDecoder.decode(file.getRawUrl().toString(), StandardCharsets.UTF_8)).append('\n') + } } + errMessage } - log.error { errMessage } } private fun getExtensionDataFolder(extensionArtifact: Artifact): File {