Logging¶
In this library we are using KSLog for logging of events in telegram bots. There are several ways to set it up and configure.
// (1)
setDefaultKSLog(
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
println(defaultMessageFormatter(level, tag, message, throwable))
}
)
// (2)
DefaultKTgBotAPIKSLog = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
println(defaultMessageFormatter(level, tag, message, throwable))
}
// (3)
val bot = telegramBot(YOUR_TOKEN) {
logger = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
println(defaultMessageFormatter(level, tag, message, throwable))
}
}
- This variant will set GLOBAL DEFAULT logger. For example, if you will use somewhere
TagLogger
, it will useKSLog.default
under the hood - All the bots created after this setup will use new logger until more specified logger configured (see below)
- Passing of
logger
variable to theKtorRequestsExecutor
or one of factoriestelegrabBot
will lead to granular setup of logging