mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-12-22 14:07:15 +00:00
start implement lazy messages api
This commit is contained in:
parent
88859ffab8
commit
10576d32f6
7
src/commonMain/kotlin/CallbackKSLog.kt
Normal file
7
src/commonMain/kotlin/CallbackKSLog.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
class CallbackKSLog(
|
||||
private val performLogCallback: (level: LogLevel, tag: String?, message: String, throwable: Throwable?) -> Unit
|
||||
) : KSLog {
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = performLogCallback(level, tag, message, throwable)
|
||||
}
|
26
src/commonMain/kotlin/DefaultKSLog.kt
Normal file
26
src/commonMain/kotlin/DefaultKSLog.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
class DefaultKSLog(
|
||||
private val defaultTag: String,
|
||||
private val filter: MessageFilter = { _, _, _, _ -> true },
|
||||
private val messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
private val logging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit
|
||||
) : KSLog {
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun performLog(level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> String) {
|
||||
super.performLog(level, tag, throwable, messageBuilder)
|
||||
}
|
||||
|
||||
override suspend fun performLog(
|
||||
level: LogLevel,
|
||||
tag: String?,
|
||||
throwable: Throwable?,
|
||||
messageBuilder: suspend () -> String
|
||||
) {
|
||||
if (filter(level, tag, ))
|
||||
super.performLog(level, tag, throwable, messageBuilder)
|
||||
}
|
||||
}
|
@ -2,72 +2,72 @@
|
||||
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
inline fun KSLog.log(level: LogLevel, tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = performLog(level, tag, messageBuilder(), e)
|
||||
inline fun KSLog.log(level: LogLevel, message: String, e: Throwable? = null) = log(level, null, e) { message }
|
||||
inline fun KSLog.log(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, e) { message }
|
||||
inline fun KSLog.log(level: LogLevel, tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = performLog(level, tag, e, messageBuilder)
|
||||
inline fun KSLog.log(level: LogLevel, message: String, e: Throwable? = null) = performLog(level, message, e)
|
||||
inline fun KSLog.log(level: LogLevel, tag: String, message: String, e: Throwable? = null) = performLog(level, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.verbose(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.VERBOSE, tag, e, messageBuilder)
|
||||
inline fun KSLog.verbose(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.VERBOSE, tag, e, messageBuilder)
|
||||
inline fun KSLog.verbose(message: String, e: Throwable? = null) = log(LogLevel.VERBOSE, message, e)
|
||||
inline fun KSLog.verbose(tag: String, message: String, e: Throwable? = null) = log(LogLevel.VERBOSE, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.info(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.INFO, tag, e, messageBuilder)
|
||||
inline fun KSLog.info(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.INFO, tag, e, messageBuilder)
|
||||
inline fun KSLog.info(message: String, e: Throwable? = null) = log(LogLevel.INFO, message, e)
|
||||
inline fun KSLog.info(tag: String, message: String, e: Throwable? = null) = log(LogLevel.INFO, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.warning(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.WARNING, tag, e, messageBuilder)
|
||||
inline fun KSLog.warning(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.WARNING, tag, e, messageBuilder)
|
||||
inline fun KSLog.warning(message: String, e: Throwable? = null) = log(LogLevel.WARNING, message, e)
|
||||
inline fun KSLog.warning(tag: String, message: String, e: Throwable? = null) = log(LogLevel.WARNING, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.error(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.ERROR, tag, e, messageBuilder)
|
||||
inline fun KSLog.error(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.ERROR, tag, e, messageBuilder)
|
||||
inline fun KSLog.error(message: String, e: Throwable? = null) = log(LogLevel.ERROR, message, e)
|
||||
inline fun KSLog.error(tag: String, message: String, e: Throwable? = null) = log(LogLevel.ERROR, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.assert(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.ASSERT, tag, e, messageBuilder)
|
||||
inline fun KSLog.assert(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.ASSERT, tag, e, messageBuilder)
|
||||
inline fun KSLog.assert(message: String, e: Throwable? = null) = log(LogLevel.ASSERT, message, e)
|
||||
inline fun KSLog.assert(tag: String, message: String, e: Throwable? = null) = log(LogLevel.ASSERT, tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.debug(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(LogLevel.DEBUG, tag, e, messageBuilder)
|
||||
inline fun KSLog.debug(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.DEBUG, tag, e, messageBuilder)
|
||||
inline fun KSLog.debug(message: String, e: Throwable? = null) = log(LogLevel.DEBUG, message, e)
|
||||
inline fun KSLog.debug(tag: String, message: String, e: Throwable? = null) = log(LogLevel.DEBUG, tag, message, e)
|
||||
|
||||
// ----- Short names
|
||||
|
||||
|
||||
inline fun KSLog.l(level: LogLevel, tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(level, tag, e, messageBuilder)
|
||||
inline fun KSLog.l(level: LogLevel, tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(level, tag, e, messageBuilder)
|
||||
inline fun KSLog.l(level: LogLevel, message: String, e: Throwable? = null) = log(level, message, e)
|
||||
inline fun KSLog.l(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, message, e)
|
||||
|
||||
inline fun KSLog.v(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = verbose(tag, e, messageBuilder)
|
||||
inline fun KSLog.v(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = verbose(tag, e, messageBuilder)
|
||||
inline fun KSLog.v(message: String, e: Throwable? = null) = verbose(message, e)
|
||||
inline fun KSLog.v(tag: String, message: String, e: Throwable? = null) = verbose(tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.i(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = info(tag, e, messageBuilder)
|
||||
inline fun KSLog.i(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = info(tag, e, messageBuilder)
|
||||
inline fun KSLog.i(message: String, e: Throwable? = null) = info(message, e)
|
||||
inline fun KSLog.i(tag: String, message: String, e: Throwable? = null) = info(tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.w(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = warning(tag, e, messageBuilder)
|
||||
inline fun KSLog.w(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = warning(tag, e, messageBuilder)
|
||||
inline fun KSLog.w(message: String, e: Throwable? = null) = warning(message, e)
|
||||
inline fun KSLog.w(tag: String, message: String, e: Throwable? = null) = warning(tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.e(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = error(tag, e, messageBuilder)
|
||||
inline fun KSLog.e(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = error(tag, e, messageBuilder)
|
||||
inline fun KSLog.e(message: String, e: Throwable? = null) = error(message, e)
|
||||
inline fun KSLog.e(tag: String, message: String, e: Throwable? = null) = error(tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.wtf(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = assert(tag, e, messageBuilder)
|
||||
inline fun KSLog.wtf(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = assert(tag, e, messageBuilder)
|
||||
inline fun KSLog.wtf(message: String, e: Throwable? = null) = assert(message, e)
|
||||
inline fun KSLog.wtf(tag: String, message: String, e: Throwable? = null) = assert(tag, message, e)
|
||||
|
||||
|
||||
inline fun KSLog.d(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = debug(tag, e, messageBuilder)
|
||||
inline fun KSLog.d(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = debug(tag, e, messageBuilder)
|
||||
inline fun KSLog.d(message: String, e: Throwable? = null) = debug(message, e)
|
||||
inline fun KSLog.d(tag: String, message: String, e: Throwable? = null) = debug(tag, message, e)
|
||||
|
@ -12,6 +12,19 @@ enum class LogLevel {
|
||||
|
||||
interface KSLog {
|
||||
fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?)
|
||||
fun performLog(level: LogLevel, message: String, throwable: Throwable?) = performLog(level, null, message, throwable)
|
||||
fun performLog(
|
||||
level: LogLevel,
|
||||
tag: String?,
|
||||
throwable: Throwable?,
|
||||
messageBuilder: () -> String
|
||||
) = performLog(level, tag, messageBuilder(), throwable)
|
||||
suspend fun performLog(
|
||||
level: LogLevel,
|
||||
tag: String?,
|
||||
throwable: Throwable?,
|
||||
messageBuilder: suspend () -> String
|
||||
) = performLog(level, tag, messageBuilder(), throwable)
|
||||
companion object : KSLog {
|
||||
private var defaultLogger: KSLog? = null
|
||||
var default: KSLog
|
||||
@ -30,12 +43,6 @@ interface KSLog {
|
||||
|
||||
operator fun KSLog.invoke(performLogCallback: (level: LogLevel, tag: String?, message: String, throwable: Throwable?) -> Unit) = CallbackKSLog(performLogCallback)
|
||||
|
||||
class CallbackKSLog(
|
||||
private val performLogCallback: (level: LogLevel, tag: String?, message: String, throwable: Throwable?) -> Unit
|
||||
) : KSLog {
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = performLogCallback(level, tag, message, throwable)
|
||||
}
|
||||
|
||||
expect fun KSLog(
|
||||
defaultTag: String,
|
||||
filter: MessageFilter = { _, _, _, _ -> true },
|
||||
|
Loading…
Reference in New Issue
Block a user