AbstractLoggerController

This commit is contained in:
Karlatemp 2020-10-30 18:14:09 +08:00
parent f1113bbcce
commit ada3c8f375
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
6 changed files with 38 additions and 28 deletions

View File

@ -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

View File

@ -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))
}

View File

@ -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

View File

@ -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))
}

View File

@ -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)
}
}
}

View File

@ -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