Improve logs

This commit is contained in:
Him188 2020-12-27 18:51:26 +08:00
parent e38fb5c1d0
commit 7fe0eb23b6

View File

@ -289,7 +289,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
return return
} }
logger.info { "开始加载好友信息" } logger.info { "Start loading friend list..." }
var currentFriendCount = 0 var currentFriendCount = 0
var totalFriendCount: Short var totalFriendCount: Short
while (true) { while (true) {
@ -311,13 +311,13 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
FriendImpl(bot, bot.coroutineContext, it.toMiraiFriendInfo()) FriendImpl(bot, bot.coroutineContext, it.toMiraiFriendInfo())
).also { currentFriendCount++ } ).also { currentFriendCount++ }
} }
logger.verbose { "正在加载好友列表 ${currentFriendCount}/${totalFriendCount}" } logger.verbose { "Loading friend list: ${currentFriendCount}/${totalFriendCount}" }
if (currentFriendCount >= totalFriendCount) { if (currentFriendCount >= totalFriendCount) {
break break
} }
// delay(200) // delay(200)
} }
logger.info { "好友列表加载完成, 共 ${currentFriendCount}" } logger.info { "Successfully loaded friend list: $currentFriendCount in total" }
initFriendOk = true initFriendOk = true
} }
@ -345,7 +345,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
return return
} }
logger.info { "开始加载群组列表与群成员列表" } logger.info { "Start loading group list..." }
val troopListData = FriendList.GetTroopListSimplify(bot.client) val troopListData = FriendList.GetTroopListSimplify(bot.client)
.sendAndExpect<FriendList.GetTroopListSimplify.Response>(retry = 5) .sendAndExpect<FriendList.GetTroopListSimplify.Response>(retry = 5)
@ -358,14 +358,14 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
} }
} }
} }
logger.info { "群组列表与群成员加载完成, 共 ${troopListData.groups.size}" } logger.info { "Successfully loaded group list: ${troopListData.groups.size} in total." }
initGroupOk = true initGroupOk = true
} }
override suspend fun init(): Unit = coroutineScope { override suspend fun init(): Unit = coroutineScope {
check(bot.isActive) { "bot is dead therefore network can't init" } check(bot.isActive) { "bot is dead therefore network can't init." }
check(this@QQAndroidBotNetworkHandler.isActive) { "network is dead therefore can't init" } check(this@QQAndroidBotNetworkHandler.isActive) { "network is dead therefore can't init." }
CancellationException("re-init").let { reInitCancellationException -> CancellationException("re-init").let { reInitCancellationException ->
if (!initFriendOk) { if (!initFriendOk) {
@ -387,16 +387,16 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
} }
this@QQAndroidBotNetworkHandler.launch(CoroutineName("Awaiting ConfigPushSvc.PushReq")) { this@QQAndroidBotNetworkHandler.launch(CoroutineName("Awaiting ConfigPushSvc.PushReq")) {
logger.info { "Awaiting ConfigPushSvc.PushReq" } logger.info { "Awaiting ConfigPushSvc.PushReq." }
when (val resp: ConfigPushSvc.PushReq.PushReqResponse? = nextEventOrNull(10_000)) { when (val resp: ConfigPushSvc.PushReq.PushReqResponse? = nextEventOrNull(10_000)) {
null -> logger.info { "Missing ConfigPushSvc.PushReq." } null -> logger.info { "Missing ConfigPushSvc.PushReq." }
is ConfigPushSvc.PushReq.PushReqResponse.Success -> { is ConfigPushSvc.PushReq.PushReqResponse.Success -> {
logger.info { "ConfigPushSvc.PushReq: Success" } logger.info { "ConfigPushSvc.PushReq: Success." }
} }
is ConfigPushSvc.PushReq.PushReqResponse.ChangeServer -> { is ConfigPushSvc.PushReq.PushReqResponse.ChangeServer -> {
logger.info { "Server requires reconnect." } bot.logger.info { "Server requires reconnect." }
logger.info { "ChangeServer.unknown = ${resp.unknown}" } logger.debug { "ChangeServer.unknown = ${resp.unknown}." }
logger.info { "Server list: ${resp.serverList.joinToString()}" } bot.logger.info { "Server list: ${resp.serverList.joinToString()}." }
resp.serverList.forEach { resp.serverList.forEach {
bot.client.serverList.add(it.host to it.port) bot.client.serverList.add(it.host to it.port)
@ -421,7 +421,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
it.consumer.cast() // IDE false positive warning it.consumer.cast() // IDE false positive warning
) )
}.getOrElse { }.getOrElse {
logger.error("Exception on processing pendingIncomingPackets", it) logger.error("Exception on processing pendingIncomingPackets.", it)
} }
} }
val list = pendingIncomingPackets val list = pendingIncomingPackets
@ -431,7 +431,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
runCatching { runCatching {
BotOnlineEvent(bot).broadcast() BotOnlineEvent(bot).broadcast()
}.getOrElse { }.getOrElse {
logger.error("Exception on broadcasting BotOnlineEvent", it) logger.error("Exception on broadcasting BotOnlineEvent.", it)
} }
Unit // dont remove. can help type inference Unit // dont remove. can help type inference
@ -451,8 +451,8 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
launch(CoroutineName("Syncing friend message history")) { syncFromEvent<MessageSvcPbGetMsg.GetMsgSuccess, Unit> { } } launch(CoroutineName("Syncing friend message history")) { syncFromEvent<MessageSvcPbGetMsg.GetMsgSuccess, Unit> { } }
MessageSvcPbGetMsg(bot.client, MsgSvc.SyncFlag.START, null).sendAndExpect<Packet>() MessageSvcPbGetMsg(bot.client, MsgSvc.SyncFlag.START, null).sendAndExpect<Packet>()
} ?: error("timeout syncing friend message history") } ?: error("timeout syncing friend message history.")
logger.info { "Syncing friend message history: Success" } logger.info { "Syncing friend message history: Success." }
} }
private suspend fun doHeartBeat(): Throwable? { private suspend fun doHeartBeat(): Throwable? {