mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Allow FrontEnd to implement LoggerController
This commit is contained in:
parent
544e11747c
commit
abb55ac619
@ -172,6 +172,11 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
|||||||
*/
|
*/
|
||||||
public fun createLogger(identity: String?): MiraiLogger
|
public fun createLogger(identity: String?): MiraiLogger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前端预先定义的 [LoggerController], 以允许前端使用自己的配置系统
|
||||||
|
*/
|
||||||
|
public val loggerController: LoggerController get() = LoggerControllerImpl
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
internal lateinit var instance: MiraiConsoleImplementation
|
internal lateinit var instance: MiraiConsoleImplementation
|
||||||
private val initLock = ReentrantLock()
|
private val initLock = ReentrantLock()
|
||||||
|
@ -12,13 +12,14 @@ package net.mamoe.mirai.console.extensions
|
|||||||
|
|
||||||
import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint
|
import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint
|
||||||
import net.mamoe.mirai.console.extension.SingletonExtension
|
import net.mamoe.mirai.console.extension.SingletonExtension
|
||||||
|
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
||||||
import net.mamoe.mirai.console.logging.LoggerController
|
import net.mamoe.mirai.console.logging.LoggerController
|
||||||
import net.mamoe.mirai.console.permission.PermissionService
|
import net.mamoe.mirai.console.permission.PermissionService
|
||||||
|
|
||||||
public interface LoggerControllerProvider : SingletonExtension<LoggerController> {
|
public interface LoggerControllerProvider : SingletonExtension<LoggerController> {
|
||||||
public companion object ExtensionPoint :
|
public companion object ExtensionPoint :
|
||||||
AbstractSingletonExtensionPoint<LoggerControllerProvider, LoggerController>(LoggerControllerProvider::class, LoggerControllerImpl)
|
AbstractSingletonExtensionPoint<LoggerControllerProvider, LoggerController>(LoggerControllerProvider::class, MiraiConsoleImplementationBridge.frontendLoggerController)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelec
|
|||||||
import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage
|
import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage
|
||||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate
|
import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate
|
||||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
||||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerTrusted
|
|
||||||
import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger
|
import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger
|
||||||
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
|
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
|
||||||
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
|
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
|
||||||
@ -88,10 +87,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns
|
override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns
|
||||||
override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns
|
override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns
|
||||||
override val consoleInput: ConsoleInput by instance::consoleInput
|
override val consoleInput: ConsoleInput by instance::consoleInput
|
||||||
private val loggerController = LoggerControllerDelegate(LoggerControllerTrusted)
|
|
||||||
override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver =
|
override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver =
|
||||||
instance.createLoginSolver(requesterBot, configuration)
|
instance.createLoginSolver(requesterBot, configuration)
|
||||||
|
|
||||||
|
internal val frontendLoggerController = instance.loggerController
|
||||||
|
override val loggerController: LoggerControllerDelegate = LoggerControllerDelegate(frontendLoggerController)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
DefaultLogger = this::createLogger
|
DefaultLogger = this::createLogger
|
||||||
}
|
}
|
||||||
@ -106,10 +107,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
internal fun doStart() {
|
internal fun doStart() {
|
||||||
|
|
||||||
phase `pre setup logger controller`@{
|
phase `pre setup logger controller`@{
|
||||||
loggerController.delegate = LoggerControllerImpl
|
loggerController.delegate = frontendLoggerController
|
||||||
|
if (frontendLoggerController === LoggerControllerImpl) {
|
||||||
// Relaod LoggerConfig first.
|
// Relaod LoggerConfig first.
|
||||||
ConsoleDataScope.addAndReloadConfig(LoggerConfig)
|
ConsoleDataScope.addAndReloadConfig(LoggerConfig)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
phase `greeting`@{
|
phase `greeting`@{
|
||||||
val buildDateFormatted =
|
val buildDateFormatted =
|
||||||
@ -179,7 +182,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
|
|
||||||
phase `setup logger controller`@{
|
phase `setup logger controller`@{
|
||||||
val selected = LoggerControllerProvider.selectedInstance
|
val selected = LoggerControllerProvider.selectedInstance
|
||||||
if (selected !== LoggerControllerImpl) {
|
if (selected !== frontendLoggerController) {
|
||||||
ConsoleDataScope.dropConfig(LoggerConfig)
|
ConsoleDataScope.dropConfig(LoggerConfig)
|
||||||
loggerController.delegate = selected
|
loggerController.delegate = selected
|
||||||
}
|
}
|
||||||
|
@ -1,18 +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 via the following link.
|
|
||||||
*
|
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.mamoe.mirai.console.internal.logging
|
|
||||||
|
|
||||||
import net.mamoe.mirai.console.logging.LoggerController
|
|
||||||
import net.mamoe.mirai.utils.SimpleLogger
|
|
||||||
|
|
||||||
internal object LoggerControllerTrusted: LoggerController {
|
|
||||||
override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user