From 3a5fa11554cb8f631d22bac640bee3e99cdb9a14 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 8 Nov 2020 10:49:57 +0800 Subject: [PATCH] Move LogPriority into AbstractLoggerController --- .../internal/data/builtins/LoggerConfig.kt | 8 ++-- .../internal/logging/LoggerControllerImpl.kt | 1 - .../src/logging/AbstractLoggerController.kt | 34 +++++++++++++++ .../mirai-console/src/logging/LogPriority.kt | 43 ------------------- 4 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 backend/mirai-console/src/logging/LogPriority.kt diff --git a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index adaa2fa5e..f860e104a 100644 --- a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -12,19 +12,19 @@ package net.mamoe.mirai.console.internal.data.builtins import net.mamoe.mirai.console.data.AutoSavePluginConfig import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value -import net.mamoe.mirai.console.logging.LogPriority +import net.mamoe.mirai.console.logging.AbstractLoggerController internal object LoggerConfig : AutoSavePluginConfig("Logger") { @ValueDescription(""" 日志输出等级 可选值: ALL, VERBOSE, DEBUG, INFO, WARNING, ERROR, NONE """) - val defaultPriority by value(LogPriority.INFO) + val defaultPriority by value(AbstractLoggerController.LogPriority.INFO) @ValueDescription(""" 特定日志记录器输出等级 """) - val loggers: Map by value( - mapOf("example.logger" to LogPriority.NONE) + val loggers: Map by value( + mapOf("example.logger" to AbstractLoggerController.LogPriority.NONE) ) } diff --git a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index f828f5e86..c65a23237 100644 --- a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -12,7 +12,6 @@ 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.util.ConsoleInternalApi @ConsoleFrontEndImplementation diff --git a/backend/mirai-console/src/logging/AbstractLoggerController.kt b/backend/mirai-console/src/logging/AbstractLoggerController.kt index 19dc9b7f6..3d4725990 100644 --- a/backend/mirai-console/src/logging/AbstractLoggerController.kt +++ b/backend/mirai-console/src/logging/AbstractLoggerController.kt @@ -11,6 +11,7 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.SimpleLogger +import java.util.* @ConsoleExperimentalApi public abstract class AbstractLoggerController : LoggerController { @@ -25,4 +26,37 @@ public abstract class AbstractLoggerController : LoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = shouldLog(LogPriority.by(priority), getPriority(identity)) + @Suppress("unused") + @ConsoleExperimentalApi + public enum class LogPriority { + ALL(null), + VERBOSE, + DEBUG, + INFO, + WARNING, + ERROR, + NONE(null); + + private var mapped: SimpleLogger.LogPriority? = null + + public companion object { + private val mapping = EnumMap(SimpleLogger.LogPriority::class.java) + + public fun by(priority: SimpleLogger.LogPriority): LogPriority = mapping[priority]!! + + init { + values().forEach { priority -> + mapping[priority.mapped ?: return@forEach] = priority + } + } + } + + @Suppress("UNUSED_PARAMETER") + constructor(void: Nothing?) + constructor() { + mapped = SimpleLogger.LogPriority.valueOf(name) + } + + } + } diff --git a/backend/mirai-console/src/logging/LogPriority.kt b/backend/mirai-console/src/logging/LogPriority.kt deleted file mode 100644 index c6ad127af..000000000 --- a/backend/mirai-console/src/logging/LogPriority.kt +++ /dev/null @@ -1,43 +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 through the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - -package net.mamoe.mirai.console.logging - -import net.mamoe.mirai.utils.SimpleLogger -import java.util.* - -public enum class LogPriority { - ALL(null), - VERBOSE, - DEBUG, - INFO, - WARNING, - ERROR, - NONE(null); - - private var mapped: SimpleLogger.LogPriority? = null - - public companion object { - private val mapping = EnumMap(SimpleLogger.LogPriority::class.java) - - public fun by(priority: SimpleLogger.LogPriority): LogPriority = mapping[priority]!! - - init { - values().forEach { priority -> - mapping[priority.mapped ?: return@forEach] = priority - } - } - } - - constructor(void: Nothing?) - constructor() { - mapped = SimpleLogger.LogPriority.valueOf(name) - } - -}