mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Improve logging of plugin loading; close #369
- Log plugin version when loading plugin - Log plugin loading/enabling status when verbose enabled
This commit is contained in:
parent
be928efb75
commit
ee48adfd8c
@ -23,6 +23,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoadException
|
||||
import net.mamoe.mirai.console.plugin.name
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.verbose
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@ -103,11 +104,12 @@ internal object BuiltInJvmPluginLoaderImpl :
|
||||
if (loadedPlugins.put(plugin, Unit) != null) {
|
||||
error("Plugin '${plugin.name}' is already loaded and cannot be reloaded.")
|
||||
}
|
||||
logger.verbose { "Loading plugin ${plugin.description.smartToString()}" }
|
||||
runCatching {
|
||||
check(plugin is JvmPluginInternal) { "A JvmPlugin must extend AbstractJvmPlugin to be loaded by JvmPluginLoader.BuiltIn" }
|
||||
plugin.internalOnLoad()
|
||||
}.getOrElse {
|
||||
throw PluginLoadException("Exception while loading ${plugin.description.name}", it)
|
||||
throw PluginLoadException("Exception while loading ${plugin.description.smartToString()}", it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,9 +117,13 @@ internal object BuiltInJvmPluginLoaderImpl :
|
||||
if (plugin.isEnabled) error("Plugin '${plugin.name}' is already enabled and cannot be re-enabled.")
|
||||
ensureActive()
|
||||
runCatching {
|
||||
logger.verbose { "Enabling plugin ${plugin.description.smartToString()}" }
|
||||
if (plugin is JvmPluginInternal) {
|
||||
plugin.internalOnEnable()
|
||||
} else plugin.onEnable()
|
||||
|
||||
// Extra space for logging align
|
||||
logger.verbose { "Enabled plugin ${plugin.description.smartToString()}" }
|
||||
}.getOrElse {
|
||||
throw PluginLoadException("Exception while loading ${plugin.description.name}", it)
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.plugin
|
||||
|
||||
import net.mamoe.mirai.console.plugin.description.PluginDescription
|
||||
|
||||
internal fun PluginDescription.smartToString(): String {
|
||||
return "$name v$version"
|
||||
}
|
@ -86,10 +86,10 @@ internal object PluginManagerImpl : PluginManager, CoroutineScope by MiraiConsol
|
||||
resolvedPlugins.add(plugin)
|
||||
}.fold(
|
||||
onSuccess = {
|
||||
logger.info { "Successfully loaded plugin ${getPluginDescription(plugin).name}" }
|
||||
logger.info { "Successfully loaded plugin ${getPluginDescription(plugin).smartToString()}" }
|
||||
},
|
||||
onFailure = {
|
||||
logger.info { "Cannot load plugin ${getPluginDescription(plugin).name}" }
|
||||
logger.info { "Cannot load plugin ${getPluginDescription(plugin).smartToString()}" }
|
||||
throw it
|
||||
}
|
||||
)
|
||||
@ -101,10 +101,10 @@ internal object PluginManagerImpl : PluginManager, CoroutineScope by MiraiConsol
|
||||
this.enable(plugin as P)
|
||||
}.fold(
|
||||
onSuccess = {
|
||||
logger.info { "Successfully enabled plugin ${getPluginDescription(plugin).name}" }
|
||||
logger.info { "Successfully enabled plugin ${getPluginDescription(plugin).smartToString()}" }
|
||||
},
|
||||
onFailure = {
|
||||
logger.info { "Cannot enable plugin ${getPluginDescription(plugin).name}" }
|
||||
logger.info { "Cannot enable plugin ${getPluginDescription(plugin).smartToString()}" }
|
||||
throw it
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user