mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-11-18 06:03:47 +00:00
it's relovution, Johny
This commit is contained in:
parent
3f600f3691
commit
95779af7b6
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
* All the platform specific logged factories has been renamed
|
||||||
|
|
||||||
## 0.0.3
|
## 0.0.3
|
||||||
|
|
||||||
* Fixes in `JVM` logging
|
* Fixes in `JVM` logging
|
||||||
|
@ -9,5 +9,5 @@ android.enableJetifier=true
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.0.3
|
version=0.1.0
|
||||||
android_code_version=3
|
android_code_version=4
|
||||||
|
@ -37,10 +37,14 @@ class CallbackKSLog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
expect fun KSLog(
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
||||||
) : KSLog
|
) : KSLog = KSLog { l, t, m, e ->
|
||||||
|
if (filter(l, t ?: defaultTag, m, e)) {
|
||||||
|
KSLog.default.performLog(l, t ?: defaultTag, m, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun KSLog(
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
@ -52,7 +56,7 @@ fun KSLog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun KSLog(
|
fun KSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
firstLevel: LogLevel,
|
firstLevel: LogLevel,
|
||||||
secondLevel: LogLevel,
|
secondLevel: LogLevel,
|
||||||
|
5
src/commonMain/kotlin/MessageFormatterTypealias.kt
Normal file
5
src/commonMain/kotlin/MessageFormatterTypealias.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.kslog.common
|
||||||
|
|
||||||
|
typealias MessageFormatter = (l: LogLevel, t: String, m: String, Throwable?) -> String
|
||||||
|
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] $t - $m" }
|
||||||
|
|
@ -1,11 +1,12 @@
|
|||||||
package dev.inmo.kslog.common
|
package dev.inmo.kslog.common
|
||||||
|
|
||||||
fun KSLog(
|
fun KSJSLog(
|
||||||
messageFormatter: (l: LogLevel, t: String?, m: String, Throwable?) -> String,
|
defaultTag: String,
|
||||||
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
||||||
) = KSLog { l, t, m, e ->
|
) = KSLog { l, t, m, e ->
|
||||||
if (!filter(l, t, m, e)) return@KSLog
|
if (!filter(l, t, m, e)) return@KSLog
|
||||||
val text = messageFormatter(l,t,m,e)
|
val text = messageFormatter(l, t?:defaultTag, m, e)
|
||||||
val args = e ?.let {
|
val args = e ?.let {
|
||||||
arrayOf(text, e)
|
arrayOf(text, e)
|
||||||
} ?: arrayOf(text)
|
} ?: arrayOf(text)
|
||||||
@ -19,12 +20,29 @@ fun KSLog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun KSLog(
|
fun KSJSLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
|
levels: Iterable<LogLevel>
|
||||||
): KSLog {
|
): KSLog {
|
||||||
return KSLog(
|
val levels = levels.toSet()
|
||||||
{ l, t, m, _ -> "[$l] ${t ?: defaultTag} - $m" },
|
return KSJSLog (defaultTag, messageFormatter) { l, _, _, _ ->
|
||||||
{ l, t, m, e -> filter(l, t ?: defaultTag, m, e) }
|
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.VERBOSE
|
||||||
|
): KSLog = KSJSLog (defaultTag, messageFormatter) { l, _, _, _ ->
|
||||||
|
minLoggingLevel.ordinal <= l.ordinal
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,14 @@ package dev.inmo.kslog.common
|
|||||||
|
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
fun KSLog(
|
fun KSJVMLog(
|
||||||
|
defaultTag: String,
|
||||||
logger: java.util.logging.Logger,
|
logger: java.util.logging.Logger,
|
||||||
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean,
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
messageFormatter: (l: LogLevel, t: String?, m: String, Throwable?) -> String
|
filter: (l: LogLevel, t: String?, m: String, Throwable?) -> Boolean
|
||||||
) = KSLog { l, t, m, e ->
|
) = KSLog { l, t, m, e ->
|
||||||
if (!filter(l, t, m, e)) return@KSLog
|
if (!filter(l, t, m, e)) return@KSLog
|
||||||
val text = messageFormatter(l,t,m,e)
|
val text = messageFormatter(l,t ?: defaultTag,m,e)
|
||||||
logger.log(
|
logger.log(
|
||||||
when(l) {
|
when(l) {
|
||||||
LogLevel.VERBOSE -> Level.FINEST
|
LogLevel.VERBOSE -> Level.FINEST
|
||||||
@ -23,24 +24,32 @@ fun KSLog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KSLog(
|
fun KSJVMLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
logger: java.util.logging.Logger,
|
logger: java.util.logging.Logger,
|
||||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean = { _, _, _, _ -> true }
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
|
levels: Iterable<LogLevel>
|
||||||
): KSLog {
|
): KSLog {
|
||||||
return KSLog(
|
val levels = levels.toSet()
|
||||||
logger,
|
return KSJVMLog (defaultTag, logger, messageFormatter) { l, _, _, _ ->
|
||||||
{ l, t, m, e -> filter(l, t ?: defaultTag, m, e) }
|
l in levels
|
||||||
) { _, t, m, _ -> "${t ?: defaultTag} - $m" }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun KSLog(
|
fun KSJVMLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
logger: java.util.logging.Logger,
|
||||||
): KSLog {
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
return KSLog(
|
firstLevel: LogLevel,
|
||||||
defaultTag,
|
secondLevel: LogLevel,
|
||||||
logger = java.util.logging.Logger.getAnonymousLogger(),
|
vararg otherLevels: LogLevel
|
||||||
filter = { l, t, m, e -> filter(l, t, m, e) }
|
): KSLog = KSJVMLog (defaultTag, logger, messageFormatter, setOf(firstLevel, secondLevel, *otherLevels))
|
||||||
)
|
|
||||||
|
fun KSJVMLog(
|
||||||
|
defaultTag: String,
|
||||||
|
logger: java.util.logging.Logger,
|
||||||
|
messageFormatter: MessageFormatter = defaultMessageFormatter,
|
||||||
|
minLoggingLevel: LogLevel = LogLevel.VERBOSE
|
||||||
|
): KSLog = KSJVMLog (defaultTag, logger, messageFormatter) { l, _, _, _ ->
|
||||||
|
minLoggingLevel.ordinal <= l.ordinal
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,42 @@ package dev.inmo.kslog.common
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
|
||||||
actual fun KSLog(
|
fun KSAndroidLog(
|
||||||
defaultTag: String,
|
defaultTag: String,
|
||||||
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
filter: (l: LogLevel, t: String, m: String, Throwable?) -> Boolean
|
||||||
): KSLog {
|
) = KSLog { l, t, m, e ->
|
||||||
return KSLog { l, t, m, e ->
|
if (!filter(l, t ?: defaultTag, m, e)) return@KSLog
|
||||||
val tag = t ?: defaultTag
|
val tag = t ?: defaultTag
|
||||||
if (!filter(l, t ?: defaultTag, m, e)) return@KSLog
|
when(l) {
|
||||||
when(l) {
|
LogLevel.VERBOSE -> Log.v(tag, m, e)
|
||||||
LogLevel.VERBOSE -> Log.v(tag, m, e)
|
LogLevel.INFO -> Log.i(tag, m, e)
|
||||||
LogLevel.INFO -> Log.i(tag, m, e)
|
LogLevel.WARNING -> Log.w(tag, m, e)
|
||||||
LogLevel.WARNING -> Log.w(tag, m, e)
|
LogLevel.ERROR -> Log.e(tag, m, e)
|
||||||
LogLevel.ERROR -> Log.e(tag, m, e)
|
LogLevel.ASSERT -> Log.wtf(tag, m, e)
|
||||||
LogLevel.ASSERT -> Log.wtf(tag, m, e)
|
LogLevel.DEBUG -> Log.d(tag, m, e)
|
||||||
LogLevel.DEBUG -> Log.d(tag, m, 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