Convert DEFAULT_BLACKLIST to function and initialize the immutable set only once

This commit is contained in:
Him188 2021-06-08 16:16:01 +08:00
parent 65a3ffc147
commit f9da72c136

View File

@ -36,7 +36,7 @@ internal interface PacketLoggingStrategy {
internal class PacketLoggingStrategyImpl( internal class PacketLoggingStrategyImpl(
private val bot: AbstractBot, private val bot: AbstractBot,
private val blacklist: Set<String> = DEFAULT_BLACKLIST, private val blacklist: Set<String> = getDefaultBlacklist(),
) : PacketLoggingStrategy { ) : PacketLoggingStrategy {
override fun logSent(logger: MiraiLogger, outgoingPacket: OutgoingPacket) { override fun logSent(logger: MiraiLogger, outgoingPacket: OutgoingPacket) {
if (outgoingPacket.commandName in blacklist) return if (outgoingPacket.commandName in blacklist) return
@ -83,24 +83,27 @@ internal class PacketLoggingStrategyImpl(
} }
companion object { companion object {
val DEFAULT_BLACKLIST: Set<String> fun getDefaultBlacklist(): Set<String> {
get() { if (systemProp("mirai.debug.network.show.verbose.packets", false)) return emptySet()
if (systemProp("mirai.debug.network.show.verbose.packets", false)) return emptySet() return DEFAULT_BLACKLIST
return setOf( }
// C2C event sync, too verbose to show.
"MessageSvc.PushNotify",
"MessageSvc.PbGetMsg",
"MessageSvc.PbDeleteMsg",
// Group event sync, decoded as specific events, to optimize logs. private val DEFAULT_BLACKLIST: Set<String> by lazy {
"OnlinePush.ReqPush", setOf(
"OnlinePush.RespPush", // C2C event sync, too verbose to show.
"MessageSvc.PushNotify",
"MessageSvc.PbGetMsg",
"MessageSvc.PbDeleteMsg",
// Periodic heartbeat, showing them does not help anything. // Group event sync, decoded as specific events, to optimize logs.
"Heartbeat.Alive", "OnlinePush.ReqPush",
"StatSvc.SimpleGet", "OnlinePush.RespPush",
)
} // Periodic heartbeat, showing them does not help anything.
"Heartbeat.Alive",
"StatSvc.SimpleGet",
)
}
@JvmField @JvmField
var SHOW_PACKET_DETAILS = systemProp("mirai.debug.network.show.packet.details", false) var SHOW_PACKET_DETAILS = systemProp("mirai.debug.network.show.packet.details", false)