Unify logging in ContactCacheService

This commit is contained in:
Him188 2021-05-31 13:38:04 +08:00
parent 9dfb46d704
commit bdd390e774
3 changed files with 9 additions and 10 deletions

View File

@ -132,7 +132,7 @@ internal open class QQAndroidBot constructor(
set(BotOfflineEventMonitor, BotOfflineEventMonitorImpl())
set(BotInitProcessor, BotInitProcessorImpl(bot, components, networkLogger.subLogger("BotInitProcessor")))
set(ContactCacheService, ContactCacheServiceImpl(bot))
set(ContactCacheService, ContactCacheServiceImpl(bot, networkLogger.subLogger("ContactCacheService")))
set(ContactUpdater, ContactUpdaterImpl(bot, components, networkLogger.subLogger("ContactUpdater")))
set(
BdhSessionSyncer,

View File

@ -15,10 +15,10 @@ import kotlinx.serialization.protobuf.ProtoBuf
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.contact.info.FriendInfoImpl
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
import net.mamoe.mirai.internal.network.handler.logger
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopNum
import net.mamoe.mirai.internal.utils.ScheduledJob
import net.mamoe.mirai.internal.utils.groupCacheDir
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.createFileIfNotExists
import net.mamoe.mirai.utils.info
import net.mamoe.mirai.utils.runBIO
@ -59,6 +59,7 @@ internal fun GroupMemberListCache.isValid(stTroopNum: StTroopNum): Boolean {
internal class GroupMemberListCaches(
private val bot: QQAndroidBot,
private val logger: MiraiLogger,
) {
init {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@ -105,7 +106,7 @@ internal class GroupMemberListCaches(
file.createFileIfNotExists()
file.writeText(JsonForCache.encodeToString(GroupMemberListCache.serializer(), cache))
}
bot.network.logger.info { "Saved ${currentChanged.size} groups to local cache." }
logger.info { "Saved ${currentChanged.size} groups to local cache." }
}
}

View File

@ -16,10 +16,7 @@ import net.mamoe.mirai.internal.network.JsonForCache
import net.mamoe.mirai.internal.network.component.ComponentKey
import net.mamoe.mirai.internal.utils.ScheduledJob
import net.mamoe.mirai.internal.utils.friendCacheFile
import net.mamoe.mirai.utils.createFileIfNotExists
import net.mamoe.mirai.utils.info
import net.mamoe.mirai.utils.loadNotBlankAs
import net.mamoe.mirai.utils.runBIO
import net.mamoe.mirai.utils.*
/**
* Strategy of caching contacts. Used by [ContactUpdater].
@ -37,7 +34,8 @@ internal interface ContactCacheService {
}
internal class ContactCacheServiceImpl(
private val bot: QQAndroidBot
private val bot: QQAndroidBot,
private val logger: MiraiLogger,
) : ContactCacheService {
private val configuration get() = bot.configuration
@ -64,7 +62,7 @@ internal class ContactCacheServiceImpl(
if (!configuration.contactListCache.groupMemberListCacheEnabled) {
return@lazy null
}
GroupMemberListCaches(bot)
GroupMemberListCaches(bot, logger)
}
private val friendListSaver: ScheduledJob? by lazy {
@ -80,7 +78,7 @@ internal class ContactCacheServiceImpl(
configuration.friendCacheFile().run {
createFileIfNotExists()
writeText(JsonForCache.encodeToString(FriendListCache.serializer(), friendListCache))
bot.network.context.logger.info { "Saved ${friendListCache.list.size} friends to local cache." }
logger.info { "Saved ${friendListCache.list.size} friends to local cache." }
}
}