fixes in logging

This commit is contained in:
InsanusMokrassar 2022-06-11 19:19:19 +06:00
parent f9f56f6afb
commit 37fd9f39d3
3 changed files with 13 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package dev.inmo.plagubot
import dev.inmo.kslog.common.*
import dev.inmo.plagubot.config.*
import kotlinx.coroutines.*
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.json.jsonObject
import java.io.File

View File

@ -1,7 +1,6 @@
package dev.inmo.plagubot
import dev.inmo.kslog.common.d
import dev.inmo.kslog.common.logger
import dev.inmo.kslog.common.*
import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
@ -32,8 +31,8 @@ class HelloPlugin : Plugin {
}
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
logger.d(koin.get<HelloPluginConfig>().print)
logger.d(getMe().toString())
logger.d { koin.get<HelloPluginConfig>().print }
logger.dS { getMe().toString() }
onCommand("hello_world") {
reply(it, "Hello :)")
}

View File

@ -49,7 +49,7 @@ data class PlaguBot(
}
}
}.onFailure { e ->
logger.log(LogLevel.WARNING, "Unable to load DI part of $it", e)
logger.w("Unable to load DI part of $it", e)
}.getOrNull()
}
)
@ -59,14 +59,14 @@ data class PlaguBot(
config.plugins.map {
launch {
runCatchingSafely {
logger.info("Start loading of $it")
logger.i("Start loading of $it")
with(it) {
setupBotPlugin(koin)
}
}.onFailure { e ->
logger.log(LogLevel.WARNING, "Unable to load bot part of $it", e)
logger.w("Unable to load bot part of $it", e)
}.onSuccess {
logger.info("Complete loading of $it")
logger.i("Complete loading of $it")
}
}
}.joinAll()
@ -78,26 +78,26 @@ data class PlaguBot(
suspend fun start(
scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
): Job {
logger.info("Start initialization")
logger.i("Start initialization")
val koinApp = KoinApplication.init()
koinApp.modules(
module {
setupDI(config.databaseConfig.database, json)
}
)
logger.info("Modules loaded")
logger.i("Modules loaded")
GlobalContext.startKoin(koinApp)
logger.info("Koin started")
logger.i("Koin started")
lateinit var behaviourContext: BehaviourContext
bot.buildBehaviour(scope = scope) {
logger.info("Start setup of bot part")
logger.i("Start setup of bot part")
behaviourContext = this
setupBotPlugin(koinApp.koin)
deleteWebhook()
}
logger.info("Behaviour builder has been setup")
logger.i("Behaviour builder has been setup")
return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext).also {
logger.info("Long polling has been started")
logger.i("Long polling has been started")
}
}
}