diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 01d0b7b63..a6583fa45 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -172,6 +172,11 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public fun createLogger(identity: String?): MiraiLogger + /** + * 前端预先定义的 [LoggerController], 以允许前端使用自己的配置系统 + */ + public val loggerController: LoggerController get() = LoggerControllerImpl + public companion object { internal lateinit var instance: MiraiConsoleImplementation private val initLock = ReentrantLock() diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt index ebe84d036..43204c465 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt @@ -12,13 +12,14 @@ package net.mamoe.mirai.console.extensions import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint import net.mamoe.mirai.console.extension.SingletonExtension +import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService public interface LoggerControllerProvider : SingletonExtension { public companion object ExtensionPoint : - AbstractSingletonExtensionPoint(LoggerControllerProvider::class, LoggerControllerImpl) + AbstractSingletonExtensionPoint(LoggerControllerProvider::class, MiraiConsoleImplementationBridge.frontendLoggerController) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index cdde2d2f6..f43ec85ca 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -38,7 +38,6 @@ import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelec import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl -import net.mamoe.mirai.console.internal.logging.LoggerControllerTrusted import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl @@ -88,10 +87,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns override val consoleInput: ConsoleInput by instance::consoleInput - private val loggerController = LoggerControllerDelegate(LoggerControllerTrusted) override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) + internal val frontendLoggerController = instance.loggerController + override val loggerController: LoggerControllerDelegate = LoggerControllerDelegate(frontendLoggerController) + init { DefaultLogger = this::createLogger } @@ -106,9 +107,11 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI internal fun doStart() { phase `pre setup logger controller`@{ - loggerController.delegate = LoggerControllerImpl - // Relaod LoggerConfig first. - ConsoleDataScope.addAndReloadConfig(LoggerConfig) + loggerController.delegate = frontendLoggerController + if (frontendLoggerController === LoggerControllerImpl) { + // Relaod LoggerConfig first. + ConsoleDataScope.addAndReloadConfig(LoggerConfig) + } } phase `greeting`@{ @@ -179,7 +182,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase `setup logger controller`@{ val selected = LoggerControllerProvider.selectedInstance - if (selected !== LoggerControllerImpl) { + if (selected !== frontendLoggerController) { ConsoleDataScope.dropConfig(LoggerConfig) loggerController.delegate = selected } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt deleted file mode 100644 index eb2e16381..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.internal.logging - -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.utils.SimpleLogger - -internal object LoggerControllerTrusted: LoggerController { - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true -}