mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-11-18 06:03:47 +00:00
fixes
This commit is contained in:
parent
10576d32f6
commit
de7f735ad0
@ -1,6 +1,6 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 0.2.1
|
## 0.3.0
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
|
@ -9,5 +9,5 @@ android.enableJetifier=true
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.2.1
|
version=0.3.0
|
||||||
android_code_version=7
|
android_code_version=8
|
||||||
|
@ -2,25 +2,39 @@ package dev.inmo.kslog.common
|
|||||||
|
|
||||||
class DefaultKSLog(
|
class DefaultKSLog(
|
||||||
private val defaultTag: String,
|
private val defaultTag: String,
|
||||||
private val filter: MessageFilter = { _, _, _, _ -> true },
|
val filter: MessageFilter = { _, _, _ -> true },
|
||||||
private val messageFormatter: MessageFormatter = defaultMessageFormatter,
|
private val messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
private val logging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit
|
private val logging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit = defaultLogging
|
||||||
) : KSLog {
|
) : KSLog {
|
||||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) {
|
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) {
|
||||||
TODO("Not yet implemented")
|
val tag = tag ?: defaultTag
|
||||||
|
|
||||||
|
if (filter(level, tag, throwable)) {
|
||||||
|
val text = messageFormatter(level, tag, message, throwable)
|
||||||
|
logging(level, tag, text, throwable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun performLog(level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> String) {
|
override fun performLog(level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> String) {
|
||||||
super.performLog(level, tag, throwable, messageBuilder)
|
val tag = tag ?: defaultTag
|
||||||
|
|
||||||
|
if (filter(level, tag, throwable)) {
|
||||||
|
val text = messageFormatter(level, tag, messageBuilder(), throwable)
|
||||||
|
logging(level, tag, text, throwable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun performLog(
|
override suspend fun performLogS(
|
||||||
level: LogLevel,
|
level: LogLevel,
|
||||||
tag: String?,
|
tag: String?,
|
||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
messageBuilder: suspend () -> String
|
messageBuilder: suspend () -> String
|
||||||
) {
|
) {
|
||||||
if (filter(level, tag, ))
|
val tag = tag ?: defaultTag
|
||||||
super.performLog(level, tag, throwable, messageBuilder)
|
|
||||||
|
if (filter(level, tag, throwable)) {
|
||||||
|
val text = messageFormatter(level, tag, messageBuilder(), throwable)
|
||||||
|
logging(level, tag, text, throwable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,71 +3,85 @@
|
|||||||
package dev.inmo.kslog.common
|
package dev.inmo.kslog.common
|
||||||
|
|
||||||
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, tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = performLog(level, tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.logS(level: LogLevel, tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = performLogS(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, 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.log(level: LogLevel, tag: String, message: String, e: Throwable? = null) = performLog(level, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
|
inline fun KSLog.debug(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(LogLevel.DEBUG, tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.debugS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(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)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.verbose(tag: String? = null, e: Throwable? = null, noinline 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)
|
||||||
|
suspend inline fun KSLog.verboseS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(LogLevel.VERBOSE, tag, e, messageBuilder)
|
||||||
inline fun KSLog.verbose(message: String, e: Throwable? = null) = log(LogLevel.VERBOSE, message, e)
|
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.verbose(tag: String, message: String, e: Throwable? = null) = log(LogLevel.VERBOSE, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.info(tag: String? = null, e: Throwable? = null, noinline 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)
|
||||||
|
suspend inline fun KSLog.infoS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(LogLevel.INFO, tag, e, messageBuilder)
|
||||||
inline fun KSLog.info(message: String, e: Throwable? = null) = log(LogLevel.INFO, message, e)
|
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.info(tag: String, message: String, e: Throwable? = null) = log(LogLevel.INFO, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.warning(tag: String? = null, e: Throwable? = null, noinline 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)
|
||||||
|
suspend inline fun KSLog.warningS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(LogLevel.WARNING, tag, e, messageBuilder)
|
||||||
inline fun KSLog.warning(message: String, e: Throwable? = null) = log(LogLevel.WARNING, message, e)
|
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.warning(tag: String, message: String, e: Throwable? = null) = log(LogLevel.WARNING, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.error(tag: String? = null, e: Throwable? = null, noinline 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)
|
||||||
|
suspend inline fun KSLog.errorS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(LogLevel.ERROR, tag, e, messageBuilder)
|
||||||
inline fun KSLog.error(message: String, e: Throwable? = null) = log(LogLevel.ERROR, message, e)
|
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.error(tag: String, message: String, e: Throwable? = null) = log(LogLevel.ERROR, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.assert(tag: String? = null, e: Throwable? = null, noinline 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)
|
||||||
|
suspend inline fun KSLog.assertS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(LogLevel.ASSERT, tag, e, messageBuilder)
|
||||||
inline fun KSLog.assert(message: String, e: Throwable? = null) = log(LogLevel.ASSERT, message, e)
|
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.assert(tag: String, message: String, e: Throwable? = null) = log(LogLevel.ASSERT, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
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
|
// ----- Short names
|
||||||
|
|
||||||
|
|
||||||
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, tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = log(level, tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.lS(level: LogLevel, tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = logS(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, 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.l(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
|
inline fun KSLog.d(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = debug(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.dS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = debugS(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)
|
||||||
|
|
||||||
inline fun KSLog.v(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = verbose(tag, e, messageBuilder)
|
inline fun KSLog.v(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = verbose(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.vS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = verboseS(tag, e, messageBuilder)
|
||||||
inline fun KSLog.v(message: String, e: Throwable? = null) = verbose(message, e)
|
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.v(tag: String, message: String, e: Throwable? = null) = verbose(tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.i(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = info(tag, e, messageBuilder)
|
inline fun KSLog.i(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = info(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.iS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = infoS(tag, e, messageBuilder)
|
||||||
inline fun KSLog.i(message: String, e: Throwable? = null) = info(message, e)
|
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.i(tag: String, message: String, e: Throwable? = null) = info(tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.w(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = warning(tag, e, messageBuilder)
|
inline fun KSLog.w(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = warning(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.wS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = warningS(tag, e, messageBuilder)
|
||||||
inline fun KSLog.w(message: String, e: Throwable? = null) = warning(message, e)
|
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.w(tag: String, message: String, e: Throwable? = null) = warning(tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.e(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = error(tag, e, messageBuilder)
|
inline fun KSLog.e(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = error(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.eS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = errorS(tag, e, messageBuilder)
|
||||||
inline fun KSLog.e(message: String, e: Throwable? = null) = error(message, e)
|
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.e(tag: String, message: String, e: Throwable? = null) = error(tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
inline fun KSLog.wtf(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = assert(tag, e, messageBuilder)
|
inline fun KSLog.wtf(tag: String? = null, e: Throwable? = null, noinline messageBuilder: () -> String) = assert(tag, e, messageBuilder)
|
||||||
|
suspend inline fun KSLog.wtfS(tag: String? = null, e: Throwable? = null, noinline messageBuilder: suspend () -> String) = assertS(tag, e, messageBuilder)
|
||||||
inline fun KSLog.wtf(message: String, e: Throwable? = null) = assert(message, e)
|
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.wtf(tag: String, message: String, e: Throwable? = null) = assert(tag, message, e)
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
@ -19,7 +19,7 @@ interface KSLog {
|
|||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
messageBuilder: () -> String
|
messageBuilder: () -> String
|
||||||
) = performLog(level, tag, messageBuilder(), throwable)
|
) = performLog(level, tag, messageBuilder(), throwable)
|
||||||
suspend fun performLog(
|
suspend fun performLogS(
|
||||||
level: LogLevel,
|
level: LogLevel,
|
||||||
tag: String?,
|
tag: String?,
|
||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
@ -37,17 +37,36 @@ interface KSLog {
|
|||||||
defaultLogger = value
|
defaultLogger = value
|
||||||
}
|
}
|
||||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = default.performLog(level, tag, message, throwable)
|
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = default.performLog(level, tag, message, throwable)
|
||||||
|
override fun performLog(level: LogLevel, message: String, throwable: Throwable?) = default.performLog(level, message, throwable)
|
||||||
|
override fun performLog(
|
||||||
|
level: LogLevel,
|
||||||
|
tag: String?,
|
||||||
|
throwable: Throwable?,
|
||||||
|
messageBuilder: () -> String
|
||||||
|
) = default.performLog(level, tag, throwable, messageBuilder)
|
||||||
|
override suspend fun performLogS(
|
||||||
|
level: LogLevel,
|
||||||
|
tag: String?,
|
||||||
|
throwable: Throwable?,
|
||||||
|
messageBuilder: suspend () -> String
|
||||||
|
) = default.performLogS(level, tag, throwable, messageBuilder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
operator fun KSLog.invoke(performLogCallback: (level: LogLevel, tag: String?, message: String, throwable: Throwable?) -> Unit) = CallbackKSLog(performLogCallback)
|
operator fun KSLog.invoke(performLogCallback: (level: LogLevel, tag: String?, message: String, throwable: Throwable?) -> Unit) = CallbackKSLog(performLogCallback)
|
||||||
|
|
||||||
expect fun KSLog(
|
internal expect val defaultLogging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit
|
||||||
|
|
||||||
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
filter: MessageFilter = { _, _, _, _ -> true },
|
filter: MessageFilter = { _, _, _ -> true },
|
||||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||||
): KSLog
|
): KSLog = DefaultKSLog(
|
||||||
|
defaultTag,
|
||||||
|
filter,
|
||||||
|
messageFormatter
|
||||||
|
)
|
||||||
|
|
||||||
fun KSLog(
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
@ -55,7 +74,7 @@ fun KSLog(
|
|||||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||||
): KSLog {
|
): KSLog {
|
||||||
val levels = levels.toSet()
|
val levels = levels.toSet()
|
||||||
return KSLog (defaultTag, { l, _, _, _ ->
|
return KSLog (defaultTag, { l, _, _ ->
|
||||||
l in levels
|
l in levels
|
||||||
}, messageFormatter)
|
}, messageFormatter)
|
||||||
}
|
}
|
||||||
@ -74,7 +93,7 @@ fun KSLog(
|
|||||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
): KSLog = KSLog (
|
): KSLog = KSLog (
|
||||||
defaultTag,
|
defaultTag,
|
||||||
{ l, _, _, _ ->
|
{ l, _, _ ->
|
||||||
minLoggingLevel.ordinal <= l.ordinal
|
minLoggingLevel.ordinal <= l.ordinal
|
||||||
},
|
},
|
||||||
messageFormatter
|
messageFormatter
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.inmo.kslog.common
|
package dev.inmo.kslog.common
|
||||||
|
|
||||||
typealias MessageFormatter = (l: LogLevel, t: String, m: String, Throwable?) -> String
|
typealias MessageFormatter = (l: LogLevel, t: String, m: String, Throwable?) -> String
|
||||||
typealias MessageFilter = (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
typealias MessageFilter = (l: LogLevel, t: String?, Throwable?) -> Boolean
|
||||||
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] $t - $m" }
|
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] $t - $m" }
|
||||||
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package dev.inmo.kslog.common
|
package dev.inmo.kslog.common
|
||||||
|
|
||||||
actual fun KSLog(
|
internal actual val defaultLogging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit = { l, t, m, e ->
|
||||||
defaultTag: String,
|
|
||||||
filter: MessageFilter,
|
|
||||||
messageFormatter: MessageFormatter
|
|
||||||
): KSLog = KSLog { l, t, m, e ->
|
|
||||||
if (!filter(l, t, m, e)) return@KSLog
|
|
||||||
val text = messageFormatter(l, t?:defaultTag, m, e)
|
|
||||||
val args = e ?.let {
|
val args = e ?.let {
|
||||||
arrayOf(text, e)
|
arrayOf(m, e)
|
||||||
} ?: arrayOf(text)
|
} ?: arrayOf(m)
|
||||||
when (l) {
|
when (l) {
|
||||||
LogLevel.DEBUG -> console.log(*args)
|
LogLevel.DEBUG -> console.log(*args)
|
||||||
LogLevel.VERBOSE,
|
LogLevel.VERBOSE,
|
||||||
|
@ -3,26 +3,36 @@ package dev.inmo.kslog.common
|
|||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import java.util.logging.Logger
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
private val defaultKSLogLogger by lazy {
|
||||||
|
Logger.getLogger("KSLog")
|
||||||
|
}
|
||||||
|
private fun Logger.doLog(
|
||||||
|
l: LogLevel, t: String, m: String, e: Throwable?
|
||||||
|
) = log(
|
||||||
|
when(l) {
|
||||||
|
LogLevel.DEBUG -> Level.FINEST
|
||||||
|
LogLevel.VERBOSE -> Level.FINE
|
||||||
|
LogLevel.INFO -> Level.INFO
|
||||||
|
LogLevel.WARNING -> Level.WARNING
|
||||||
|
LogLevel.ERROR -> Level.SEVERE
|
||||||
|
LogLevel.ASSERT -> Level.SEVERE
|
||||||
|
},
|
||||||
|
m,
|
||||||
|
e
|
||||||
|
)
|
||||||
|
internal actual val defaultLogging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit = { l, t, m, e ->
|
||||||
|
defaultKSLogLogger.doLog(l, t, m, e)
|
||||||
|
}
|
||||||
|
|
||||||
fun KSLog(
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
filter: MessageFilter = { _, _, _, _ -> true },
|
filter: MessageFilter = { _, _, _ -> true },
|
||||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||||
) = KSLog { l, t, m, e ->
|
) = KSLog { l, t, m, e ->
|
||||||
if (!filter(l, t, m, e)) return@KSLog
|
if (!filter(l, t, e)) return@KSLog
|
||||||
val text = messageFormatter(l,t ?: defaultTag,m,e)
|
val text = messageFormatter(l,t ?: defaultTag,m,e)
|
||||||
logger.log(
|
logger.doLog(l, t ?: defaultTag, text, e)
|
||||||
when(l) {
|
|
||||||
LogLevel.DEBUG -> Level.FINEST
|
|
||||||
LogLevel.VERBOSE -> Level.FINE
|
|
||||||
LogLevel.INFO -> Level.INFO
|
|
||||||
LogLevel.WARNING -> Level.WARNING
|
|
||||||
LogLevel.ERROR -> Level.SEVERE
|
|
||||||
LogLevel.ASSERT -> Level.SEVERE
|
|
||||||
},
|
|
||||||
text,
|
|
||||||
e
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KSLog(
|
fun KSLog(
|
||||||
@ -32,7 +42,7 @@ fun KSLog(
|
|||||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||||
): KSLog {
|
): KSLog {
|
||||||
val levels = levels.toSet()
|
val levels = levels.toSet()
|
||||||
return KSLog (defaultTag, logger, { l, _, _, _ ->
|
return KSLog (defaultTag, logger, { l, _, _ ->
|
||||||
l in levels
|
l in levels
|
||||||
}, messageFormatter)
|
}, messageFormatter)
|
||||||
}
|
}
|
||||||
@ -51,12 +61,6 @@ fun KSLog(
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
minLoggingLevel: LogLevel = LogLevel.values().first(),
|
minLoggingLevel: LogLevel = LogLevel.values().first(),
|
||||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||||
): KSLog = KSLog (defaultTag, logger, { l, _, _, _ ->
|
): KSLog = KSLog (defaultTag, logger, { l, _, _ ->
|
||||||
minLoggingLevel.ordinal <= l.ordinal
|
minLoggingLevel.ordinal <= l.ordinal
|
||||||
}, messageFormatter)
|
}, messageFormatter)
|
||||||
|
|
||||||
actual fun KSLog(
|
|
||||||
defaultTag: String,
|
|
||||||
filter: MessageFilter,
|
|
||||||
messageFormatter: MessageFormatter
|
|
||||||
): KSLog = KSLog(defaultTag, Logger.getLogger("KSLog"), filter, messageFormatter)
|
|
||||||
|
@ -2,20 +2,14 @@ package dev.inmo.kslog.common
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
|
||||||
actual fun KSLog(
|
|
||||||
defaultTag: String,
|
internal actual val defaultLogging: (level: LogLevel, tag: String, message: String, throwable: Throwable?) -> Unit = { l, t, m, e ->
|
||||||
filter: MessageFilter,
|
|
||||||
messageFormatter: MessageFormatter
|
|
||||||
): KSLog = KSLog { l, t, m, e ->
|
|
||||||
if (!filter(l, t ?: defaultTag, m, e)) return@KSLog
|
|
||||||
val tag = t ?: defaultTag
|
|
||||||
val text = messageFormatter(l, tag, m, e)
|
|
||||||
when(l) {
|
when(l) {
|
||||||
LogLevel.DEBUG -> Log.d(tag, text, e)
|
LogLevel.DEBUG -> Log.d(t, m, e)
|
||||||
LogLevel.VERBOSE -> Log.v(tag, text, e)
|
LogLevel.VERBOSE -> Log.v(t, m, e)
|
||||||
LogLevel.INFO -> Log.i(tag, text, e)
|
LogLevel.INFO -> Log.i(t, m, e)
|
||||||
LogLevel.WARNING -> Log.w(tag, text, e)
|
LogLevel.WARNING -> Log.w(t, m, e)
|
||||||
LogLevel.ERROR -> Log.e(tag, text, e)
|
LogLevel.ERROR -> Log.e(t, m, e)
|
||||||
LogLevel.ASSERT -> Log.wtf(tag, text, e)
|
LogLevel.ASSERT -> Log.wtf(t, m, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user