console.debug logger

This commit is contained in:
Karlatemp 2020-11-09 13:33:05 +08:00
parent 8b6e2a1d9c
commit d54f4cd0d9
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
5 changed files with 19 additions and 8 deletions

View File

@ -146,7 +146,7 @@ public open class AutoSavePluginData private constructor(
} }
internal val debuggingLogger1 by lazy { internal val debuggingLogger1 by lazy {
DefaultLogger("debug").withSwitch(false) DefaultLogger("console.debug").withSwitch(false)
} }
@Suppress("RESULT_CLASS_IN_RETURN_TYPE") @Suppress("RESULT_CLASS_IN_RETURN_TYPE")

View File

@ -109,6 +109,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
if (loggerController === LoggerControllerImpl) { if (loggerController === LoggerControllerImpl) {
// Reload LoggerConfig. // Reload LoggerConfig.
ConsoleDataScope.addAndReloadConfig(LoggerConfig) ConsoleDataScope.addAndReloadConfig(LoggerConfig)
LoggerControllerImpl.initialized = true
} }
} }

View File

@ -20,6 +20,7 @@ import net.mamoe.mirai.console.command.CommandSender.Companion.toCommandSender
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.command.parse.CommandCallParser.Companion.parseCommandCall import net.mamoe.mirai.console.command.parse.CommandCallParser.Companion.parseCommandCall
import net.mamoe.mirai.console.command.resolve.CommandCallResolver.Companion.resolve import net.mamoe.mirai.console.command.resolve.CommandCallResolver.Companion.resolve
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
import net.mamoe.mirai.event.Listener import net.mamoe.mirai.event.Listener
@ -30,6 +31,7 @@ import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.message.data.asMessageChain import net.mamoe.mirai.message.data.asMessageChain
import net.mamoe.mirai.message.data.content import net.mamoe.mirai.message.data.content
import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.SimpleLogger
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
@OptIn(ExperimentalCommandDescriptors::class) @OptIn(ExperimentalCommandDescriptors::class)
@ -75,7 +77,9 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
when (val result = executeCommand(sender, message)) { when (val result = executeCommand(sender, message)) {
is CommandExecuteResult.PermissionDenied -> { is CommandExecuteResult.PermissionDenied -> {
if (!result.command.prefixOptional || message.content.startsWith(CommandManager.commandPrefix)) { if (!result.command.prefixOptional || message.content.startsWith(CommandManager.commandPrefix)) {
if (MiraiConsoleImplementationBridge.loggerController.shouldLog("console.debug", SimpleLogger.LogPriority.DEBUG)) {
sender.sendMessage("权限不足") sender.sendMessage("权限不足")
}
intercept() intercept()
} }
} }

View File

@ -24,7 +24,10 @@ internal object LoggerConfig : AutoSavePluginConfig("Logger") {
特定日志记录器输出等级 特定日志记录器输出等级
""") """)
val loggers: Map<String, AbstractLoggerController.LogPriority> by value( val loggers: Map<String, AbstractLoggerController.LogPriority> by value(
mapOf("example.logger" to AbstractLoggerController.LogPriority.NONE) mapOf(
"example.logger" to AbstractLoggerController.LogPriority.NONE,
"console.debug" to AbstractLoggerController.LogPriority.NONE,
)
) )
} }

View File

@ -17,11 +17,14 @@ import net.mamoe.mirai.console.util.ConsoleInternalApi
@ConsoleFrontEndImplementation @ConsoleFrontEndImplementation
@ConsoleInternalApi @ConsoleInternalApi
internal object LoggerControllerImpl : AbstractLoggerController() { internal object LoggerControllerImpl : AbstractLoggerController() {
internal var initialized = false
override fun getPriority(identity: String?): LogPriority = if (identity == null) { override fun getPriority(identity: String?): LogPriority {
if (!initialized) return LogPriority.NONE
return if (identity == null) {
LoggerConfig.defaultPriority LoggerConfig.defaultPriority
} else { } else {
LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority
} }
}
} }