From 96017ae862eadffd5fe846db4242fabd313ccab7 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 24 Oct 2020 19:34:16 +0800 Subject: [PATCH] MiraiConsoleLoggerController --- .../console/MiraiConsoleImplementation.kt | 10 +-- .../MiraiConsoleImplementationBridge.kt | 21 ++++++- .../internal/data/builtins/LoggerConfig.kt | 50 +++++++++++++++ .../console/logging/MiraiConsoleLogger.kt | 47 ++++++++++++++ .../logging/MiraiConsoleLoggerController.kt | 26 ++++++++ ...MiraiConsoleLoggerControllerForFrontend.kt | 39 ++++++++++++ ...iraiConsoleLoggerControllerPlatformBase.kt | 36 +++++++++++ .../logging/MiraiConsoleLoggerUnused.kt | 61 +++++++++++++++++++ .../console/logging/MiraiDelegateLogger.kt | 24 ++++++++ .../mamoe/mirai/console/TestMiraiConosle.kt | 12 ++-- .../MiraiConsoleImplementationTerminal.kt | 7 ++- 11 files changed, 316 insertions(+), 17 deletions(-) create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt 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 a1fd6347a..55281c8df 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 @@ -18,13 +18,13 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.LoginSolver -import net.mamoe.mirai.utils.MiraiLogger import java.nio.file.Path import java.util.* import java.util.concurrent.locks.ReentrantLock @@ -161,13 +161,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver - /** - * 创建一个 [MiraiLogger]. - * - * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. - * 因此不要在 [createLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] - */ - public fun createLogger(identity: String?): MiraiLogger + public val loggerController: MiraiConsoleLoggerController public companion object { internal lateinit var instance: MiraiConsoleImplementation 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 175af2331..c67694f6d 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 @@ -31,12 +31,17 @@ import net.mamoe.mirai.console.extensions.SingletonExtensionSelector import net.mamoe.mirai.console.internal.command.CommandManagerImpl import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope +import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.internal.data.castOrNull import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerUnused +import net.mamoe.mirai.console.logging.MiraiDelegateLogger import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.grantPermission import net.mamoe.mirai.console.permission.RootPermission @@ -82,6 +87,7 @@ 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 + override val loggerController: MiraiConsoleLoggerController by instance::loggerController override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) @@ -90,10 +96,22 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI DefaultLogger = this::createLogger } - override fun createLogger(identity: String?): MiraiLogger = instance.createLogger(identity) + + override fun createLogger(identity: String?): MiraiLogger { + val controller = loggerController + val logger = MiraiConsoleLoggerUnused(controller, identity) + val delegate = MiraiDelegateLogger(logger) + logger.delegateLogger = delegate + return delegate + } @Suppress("RemoveRedundantBackticks") internal fun doStart() { + phase `setup logger controller`@{ + if (loggerController is MiraiConsoleLoggerControllerForFrontend) { + ConsoleDataScope.addAndReloadConfig(LoggerConfig) + } + } phase `greeting`@{ val buildDateFormatted = buildDate.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) @@ -102,7 +120,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI mainLogger.info { "Backend: version $version, built on $buildDateFormatted." } mainLogger.info { frontEndDescription.render() } } - phase `check coroutineContext`@{ if (coroutineContext[Job] == null) { throw MalformedMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt new file mode 100644 index 000000000..da403aa53 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt @@ -0,0 +1,50 @@ +/* + * 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.data.builtins + +import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.value +import net.mamoe.mirai.utils.SimpleLogger +import java.util.* + +internal object LoggerConfig : AutoSavePluginConfig("Logger") { + val defaultPriority by value(LogPriority.INFO) + val loggers: Map by value( + mapOf("example.logger" to LogPriority.NONE) + ) + + enum class LogPriority { + ALL(null), + VERBOSE, + DEBUG, + INFO, + WARNING, + ERROR, + NONE(null); + + var mapped: SimpleLogger.LogPriority? = null + + // resolve NullPointerException + private object Holder { + @JvmField + val mapping = EnumMap(SimpleLogger.LogPriority::class.java) + } + companion object { + fun by(priority: SimpleLogger.LogPriority): LogPriority = Holder.mapping[priority]!! + } + constructor(void: Nothing?) + constructor() { + mapped = SimpleLogger.LogPriority.valueOf(name) + Holder.mapping[mapped] = this + } + + } +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt new file mode 100644 index 000000000..2c2bcf531 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt @@ -0,0 +1,47 @@ +/* + * 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.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase +import net.mamoe.mirai.utils.SimpleLogger + +internal class MiraiConsoleLogger( + private val controller: MiraiConsoleLoggerController, + val logger: MiraiLogger +) : MiraiLoggerPlatformBase() { + override val identity: String? get() = logger.identity + override val isEnabled: Boolean get() = logger.isEnabled + override fun info0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.INFO)) + logger.info(message, e) + } + + override fun warning0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.WARNING)) + logger.warning(message, e) + } + + override fun debug0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.DEBUG)) + logger.debug(message, e) + } + + override fun error0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.ERROR)) + logger.error(message, e) + } + + override fun verbose0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.VERBOSE)) + logger.verbose(message, e) + } +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt new file mode 100644 index 000000000..1c5126d1d --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt @@ -0,0 +1,26 @@ +/* + * 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.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.SimpleLogger +import java.util.concurrent.atomic.AtomicReference + +@ConsoleExperimentalApi +@ConsoleFrontEndImplementation +public interface MiraiConsoleLoggerController { + public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean + public val cacheLoggers: Boolean + public fun newLoggerImpl(identity: String?): MiraiLogger + public fun allocateLoggerRegistration(identity: String?): AtomicReference +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt new file mode 100644 index 000000000..58ee58c7e --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt @@ -0,0 +1,39 @@ +/* + * 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.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope +import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.util.ConsoleInternalApi +import net.mamoe.mirai.utils.SimpleLogger + +@ConsoleFrontEndImplementation +@ConsoleInternalApi +public abstract class MiraiConsoleLoggerControllerForFrontend : MiraiConsoleLoggerControllerPlatformBase() { + + private fun shouldLog( + priority: LoggerConfig.LogPriority, + settings: LoggerConfig.LogPriority + ): Boolean = settings <= priority + + private fun shouldLog(identity: String?, priority: LoggerConfig.LogPriority): Boolean { + return if (identity == null) { + shouldLog(priority, LoggerConfig.defaultPriority) + } else { + shouldLog(priority, LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority) + } + } + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = + shouldLog(identity, LoggerConfig.LogPriority.by(priority)) + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt new file mode 100644 index 000000000..660f03f1e --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt @@ -0,0 +1,36 @@ +/* + * 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.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.SimpleLogger +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicReference + +@Suppress("MemberVisibilityCanBePrivate") +@ConsoleExperimentalApi +@ConsoleFrontEndImplementation +public abstract class MiraiConsoleLoggerControllerPlatformBase : MiraiConsoleLoggerController { + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true + + override val cacheLoggers: Boolean + get() = true + + protected val registrations: ConcurrentHashMap> = ConcurrentHashMap() + + protected object NilIdentityPlaceholder + + override fun allocateLoggerRegistration(identity: String?): AtomicReference = + registrations.computeIfAbsent(identity ?: NilIdentityPlaceholder) { AtomicReference() } + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt new file mode 100644 index 000000000..0a7671001 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt @@ -0,0 +1,61 @@ +/* + * 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.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase + +internal class MiraiConsoleLoggerUnused( + val controller: MiraiConsoleLoggerController, + override val identity: String? +) : MiraiLoggerPlatformBase() { + internal object InitializeLock + + internal lateinit var delegateLogger: MiraiDelegateLogger + private val logger: MiraiLogger by lazy { + val logger = if (controller.cacheLoggers) { + val reference = controller.allocateLoggerRegistration(identity) + if (reference.compareAndSet(null, InitializeLock)) { + val logger = MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + reference.set(logger) + logger + } else { + // initialized/initializing + val logger: MiraiLogger + while (true) { + val status = reference.get() + if (status is MiraiLogger) { + logger = status + break + } + } + logger + } + } else { + MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + } + delegateLogger.logger = logger + logger + } + override val isEnabled: Boolean + get() = super.isEnabled + + override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) + + override fun error0(message: String?, e: Throwable?) = logger.error(message, e) + + override fun info0(message: String?, e: Throwable?) = logger.info(message, e) + + override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) + + override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt new file mode 100644 index 000000000..5f61088f7 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt @@ -0,0 +1,24 @@ +/* + * 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.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase + +internal class MiraiDelegateLogger(var logger: MiraiLogger) : MiraiLoggerPlatformBase() { + override val identity: String? get() = logger.identity + override val isEnabled: Boolean get() = logger.isEnabled + override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) + override fun error0(message: String?, e: Throwable?) = logger.error(message, e) + override fun info0(message: String?, e: Throwable?) = logger.info(message, e) + override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) + override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) +} diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index 969f03425..d3ae59a88 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -14,6 +14,8 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.data.MemoryPluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerPlatformBase import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi @@ -21,10 +23,7 @@ import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.message.data.Message -import net.mamoe.mirai.utils.BotConfiguration -import net.mamoe.mirai.utils.LoginSolver -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.PlatformLogger +import net.mamoe.mirai.utils.* import java.nio.file.Path import kotlin.coroutines.Continuation import kotlin.coroutines.CoroutineContext @@ -73,8 +72,9 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override fun createLogger(identity: String?): MiraiLogger { - return PlatformLogger(identity) + override val loggerController: MiraiConsoleLoggerController = object:MiraiConsoleLoggerControllerPlatformBase(){ + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true + override fun newLoggerImpl(identity: String?): MiraiLogger = PlatformLogger(identity) } override val coroutineContext: CoroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, throwable -> diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 1cd89f853..f20566a43 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -33,6 +33,8 @@ import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput @@ -81,7 +83,9 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override fun createLogger(identity: String?): MiraiLogger = LoggerCreator(identity) + override val loggerController: MiraiConsoleLoggerController = object : MiraiConsoleLoggerControllerForFrontend() { + override fun newLoggerImpl(identity: String?): MiraiLogger = LoggerCreator(identity) + } init { with(rootPath.toFile()) { @@ -151,6 +155,7 @@ val terminal: Terminal = run { private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription { override val name: String get() = "Terminal" override val vendor: String get() = "Mamoe Technologies" + // net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version // is console's version not frontend's version override val version: SemVersion = SemVersion(net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst)