mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-12-22 05:57:14 +00:00
rewrite of API with expect-actual and removing of redundant platform-specific factory names
This commit is contained in:
parent
f5cc748ac5
commit
be047cb8b5
@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## 0.2.0
|
||||
|
||||
* Full rewrite of API
|
||||
|
||||
## 0.1.1
|
||||
|
||||
* Changes in `JVM` levels
|
||||
|
@ -9,5 +9,5 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.1.1
|
||||
android_code_version=5
|
||||
version=0.2.0
|
||||
android_code_version=6
|
||||
|
@ -36,36 +36,39 @@ class CallbackKSLog(
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = performLogCallback(level, tag, message, throwable)
|
||||
}
|
||||
|
||||
expect fun KSLog(
|
||||
defaultTag: String,
|
||||
filter: MessageFilter = { _, _, _, _ -> true },
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||
): KSLog
|
||||
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
||||
) : KSLog = KSLog { l, t, m, e ->
|
||||
if (filter(l, t ?: defaultTag, m, e)) {
|
||||
KSLog.default.performLog(l, t ?: defaultTag, m, e)
|
||||
}
|
||||
}
|
||||
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
levels: Iterable<LogLevel>
|
||||
levels: Iterable<LogLevel>,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||
): KSLog {
|
||||
val levels = levels.toSet()
|
||||
return KSLog (defaultTag) { l, _, _, _ ->
|
||||
return KSLog (defaultTag, { l, _, _, _ ->
|
||||
l in levels
|
||||
}
|
||||
}, messageFormatter)
|
||||
}
|
||||
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
firstLevel: LogLevel,
|
||||
secondLevel: LogLevel,
|
||||
vararg otherLevels: LogLevel
|
||||
): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels))
|
||||
vararg otherLevels: LogLevel,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter)
|
||||
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
minLoggingLevel: LogLevel = LogLevel.values().first()
|
||||
): KSLog = KSLog (defaultTag) { l, _, _, _ ->
|
||||
minLoggingLevel.ordinal <= l.ordinal
|
||||
}
|
||||
minLoggingLevel: LogLevel,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
): KSLog = KSLog (
|
||||
defaultTag,
|
||||
{ l, _, _, _ ->
|
||||
minLoggingLevel.ordinal <= l.ordinal
|
||||
},
|
||||
messageFormatter
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
typealias MessageFormatter = (l: LogLevel, t: String, m: String, Throwable?) -> String
|
||||
typealias MessageFilter = (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
||||
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] $t - $m" }
|
||||
|
@ -1,10 +1,10 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
fun KSJSLog(
|
||||
actual fun KSLog(
|
||||
defaultTag: String,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
||||
) = KSLog { l, t, m, e ->
|
||||
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 {
|
||||
@ -19,30 +19,3 @@ fun KSJSLog(
|
||||
LogLevel.ASSERT -> console.error(*args)
|
||||
}
|
||||
}
|
||||
|
||||
fun KSJSLog(
|
||||
defaultTag: String,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
levels: Iterable<LogLevel>
|
||||
): KSLog {
|
||||
val levels = levels.toSet()
|
||||
return KSJSLog (defaultTag, messageFormatter) { l, _, _, _ ->
|
||||
l in levels
|
||||
}
|
||||
}
|
||||
|
||||
fun KSJSLog(
|
||||
defaultTag: String,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
firstLevel: LogLevel,
|
||||
secondLevel: LogLevel,
|
||||
vararg otherLevels: LogLevel
|
||||
): KSLog = KSJSLog (defaultTag, messageFormatter, setOf(firstLevel, secondLevel, *otherLevels))
|
||||
|
||||
fun KSJSLog(
|
||||
defaultTag: String,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
minLoggingLevel: LogLevel = LogLevel.values().first()
|
||||
): KSLog = KSJSLog (defaultTag, messageFormatter) { l, _, _, _ ->
|
||||
minLoggingLevel.ordinal <= l.ordinal
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.Logger
|
||||
|
||||
fun KSJVMLog(
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
logger: java.util.logging.Logger,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
||||
logger: Logger,
|
||||
filter: MessageFilter = { _, _, _, _ -> true },
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||
) = KSLog { l, t, m, e ->
|
||||
if (!filter(l, t, m, e)) return@KSLog
|
||||
val text = messageFormatter(l,t ?: defaultTag,m,e)
|
||||
@ -24,32 +25,38 @@ fun KSJVMLog(
|
||||
)
|
||||
}
|
||||
|
||||
fun KSJVMLog(
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
logger: java.util.logging.Logger,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
levels: Iterable<LogLevel>
|
||||
logger: Logger,
|
||||
levels: Iterable<LogLevel>,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||
): KSLog {
|
||||
val levels = levels.toSet()
|
||||
return KSJVMLog (defaultTag, logger, messageFormatter) { l, _, _, _ ->
|
||||
return KSLog (defaultTag, logger, { l, _, _, _ ->
|
||||
l in levels
|
||||
}
|
||||
}, messageFormatter)
|
||||
}
|
||||
|
||||
fun KSJVMLog(
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
logger: java.util.logging.Logger,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
logger: Logger,
|
||||
firstLevel: LogLevel,
|
||||
secondLevel: LogLevel,
|
||||
vararg otherLevels: LogLevel
|
||||
): KSLog = KSJVMLog (defaultTag, logger, messageFormatter, setOf(firstLevel, secondLevel, *otherLevels))
|
||||
|
||||
fun KSJVMLog(
|
||||
defaultTag: String,
|
||||
logger: java.util.logging.Logger,
|
||||
vararg otherLevels: LogLevel,
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||
minLoggingLevel: LogLevel = LogLevel.values().first()
|
||||
): KSLog = KSJVMLog (defaultTag, logger, messageFormatter) { l, _, _, _ ->
|
||||
): KSLog = KSLog (defaultTag, logger, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter)
|
||||
|
||||
fun KSLog(
|
||||
defaultTag: String,
|
||||
logger: Logger,
|
||||
minLoggingLevel: LogLevel = LogLevel.values().first(),
|
||||
messageFormatter: MessageFormatter = defaultMessageFormatter
|
||||
): KSLog = KSLog (defaultTag, logger, { l, _, _, _ ->
|
||||
minLoggingLevel.ordinal <= l.ordinal
|
||||
}
|
||||
}, messageFormatter)
|
||||
|
||||
actual fun KSLog(
|
||||
defaultTag: String,
|
||||
filter: MessageFilter,
|
||||
messageFormatter: MessageFormatter
|
||||
): KSLog = KSLog(defaultTag, Logger.getLogger("KSLog"), filter, messageFormatter)
|
||||
|
@ -2,42 +2,20 @@ package dev.inmo.kslog.common
|
||||
|
||||
import android.util.Log
|
||||
|
||||
fun KSAndroidLog(
|
||||
actual fun KSLog(
|
||||
defaultTag: String,
|
||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
||||
) = KSLog { 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) {
|
||||
LogLevel.DEBUG -> Log.d(tag, m, e)
|
||||
LogLevel.VERBOSE -> Log.v(tag, m, e)
|
||||
LogLevel.INFO -> Log.i(tag, m, e)
|
||||
LogLevel.WARNING -> Log.w(tag, m, e)
|
||||
LogLevel.ERROR -> Log.e(tag, m, e)
|
||||
LogLevel.ASSERT -> Log.wtf(tag, m, e)
|
||||
LogLevel.DEBUG -> Log.d(tag, text, e)
|
||||
LogLevel.VERBOSE -> Log.v(tag, text, e)
|
||||
LogLevel.INFO -> Log.i(tag, text, e)
|
||||
LogLevel.WARNING -> Log.w(tag, text, e)
|
||||
LogLevel.ERROR -> Log.e(tag, text, e)
|
||||
LogLevel.ASSERT -> Log.wtf(tag, text, e)
|
||||
}
|
||||
}
|
||||
|
||||
fun KSAndroidLog(
|
||||
defaultTag: String,
|
||||
levels: Iterable<LogLevel>
|
||||
): KSLog {
|
||||
val levels = levels.toSet()
|
||||
return KSAndroidLog (defaultTag) { l, _, _, _ ->
|
||||
l in levels
|
||||
}
|
||||
}
|
||||
|
||||
inline fun KSAndroidLog(
|
||||
defaultTag: String,
|
||||
firstLevel: LogLevel,
|
||||
secondLevel: LogLevel,
|
||||
vararg otherLevels: LogLevel
|
||||
): KSLog = KSAndroidLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels))
|
||||
|
||||
fun KSAndroidLog(
|
||||
defaultTag: String,
|
||||
minLoggingLevel: LogLevel = LogLevel.VERBOSE
|
||||
): KSLog = KSAndroidLog (defaultTag) { l, _, _, _ ->
|
||||
minLoggingLevel.ordinal <= l.ordinal
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user