From ada3c8f37593fb21f1cc2cb9f40c91890112234d Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 30 Oct 2020 18:14:09 +0800 Subject: [PATCH] AbstractLoggerController --- .../internal/data/builtins/LoggerConfig.kt | 3 +-- .../internal/logging/LoggerControllerImpl.kt | 26 +++++-------------- .../internal/logging/MiraiConsoleLogger.kt | 3 +-- .../src/logging/AbstractLoggerController.kt | 26 +++++++++++++++++++ .../mirai-console/src/logging/LogPriority.kt | 5 ++-- .../src/logging/LoggerController.kt | 3 +-- 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 backend/mirai-console/src/logging/AbstractLoggerController.kt diff --git a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index 394bc1d78..adaa2fa5e 100644 --- a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -2,10 +2,9 @@ * 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. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.data.builtins diff --git a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index 5984d5f03..f828f5e86 100644 --- a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -2,39 +2,27 @@ * 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. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.logging.AbstractLoggerController import net.mamoe.mirai.console.logging.LogPriority -import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.util.ConsoleInternalApi -import net.mamoe.mirai.utils.SimpleLogger @ConsoleFrontEndImplementation @ConsoleInternalApi -internal object LoggerControllerImpl : LoggerController { +internal object LoggerControllerImpl : AbstractLoggerController() { - private fun shouldLog( - priority: LogPriority, - settings: LogPriority - ): Boolean = settings <= priority - - private fun shouldLog(identity: String?, priority: LogPriority): Boolean { - return if (identity == null) { - shouldLog(priority, LoggerConfig.defaultPriority) - } else { - shouldLog(priority, LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority) - } + override fun getPriority(identity: String?): LogPriority = if (identity == null) { + LoggerConfig.defaultPriority + } else { + LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority } - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = - shouldLog(identity, LogPriority.by(priority)) - } \ No newline at end of file diff --git a/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt index 48b829ee9..6d4fa04a5 100644 --- a/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt +++ b/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt @@ -2,10 +2,9 @@ * 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. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.logging diff --git a/backend/mirai-console/src/logging/AbstractLoggerController.kt b/backend/mirai-console/src/logging/AbstractLoggerController.kt new file mode 100644 index 000000000..6198f1109 --- /dev/null +++ b/backend/mirai-console/src/logging/AbstractLoggerController.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 through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.SimpleLogger + +public abstract class AbstractLoggerController : LoggerController { + + protected open fun shouldLog( + priority: LogPriority, + settings: LogPriority + ): Boolean = settings <= priority + + protected abstract fun getPriority(identity: String?): LogPriority + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = + shouldLog(LogPriority.by(priority), getPriority(identity)) + +} diff --git a/backend/mirai-console/src/logging/LogPriority.kt b/backend/mirai-console/src/logging/LogPriority.kt index 957e42206..c6ad127af 100644 --- a/backend/mirai-console/src/logging/LogPriority.kt +++ b/backend/mirai-console/src/logging/LogPriority.kt @@ -2,10 +2,9 @@ * 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. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.logging @@ -41,4 +40,4 @@ public enum class LogPriority { mapped = SimpleLogger.LogPriority.valueOf(name) } -} \ No newline at end of file +} diff --git a/backend/mirai-console/src/logging/LoggerController.kt b/backend/mirai-console/src/logging/LoggerController.kt index d4124e2fb..59b60457b 100644 --- a/backend/mirai-console/src/logging/LoggerController.kt +++ b/backend/mirai-console/src/logging/LoggerController.kt @@ -2,10 +2,9 @@ * 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. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.logging