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 {
DefaultLogger("debug").withSwitch(false)
DefaultLogger("console.debug").withSwitch(false)
}
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")

View File

@ -109,6 +109,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
if (loggerController === LoggerControllerImpl) {
// Reload 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.parse.CommandCallParser.Companion.parseCommandCall
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.util.CoroutineScopeUtils.childScope
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.content
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.SimpleLogger
import java.util.concurrent.locks.ReentrantLock
@OptIn(ExperimentalCommandDescriptors::class)
@ -75,7 +77,9 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
when (val result = executeCommand(sender, message)) {
is CommandExecuteResult.PermissionDenied -> {
if (!result.command.prefixOptional || message.content.startsWith(CommandManager.commandPrefix)) {
if (MiraiConsoleImplementationBridge.loggerController.shouldLog("console.debug", SimpleLogger.LogPriority.DEBUG)) {
sender.sendMessage("权限不足")
}
intercept()
}
}

View File

@ -24,7 +24,10 @@ internal object LoggerConfig : AutoSavePluginConfig("Logger") {
特定日志记录器输出等级
""")
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
@ConsoleInternalApi
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
} else {
LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority
}
}
}