Merge pull request #8 from InsanusMokrassar/0.2.0

0.2.0
This commit is contained in:
InsanusMokrassar 2022-06-08 22:53:52 +06:00 committed by GitHub
commit 33a0d9032f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 106 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 0.2.0
* Full rewrite of API
## 0.1.1
* Changes in `JVM` levels

View File

@ -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

View File

@ -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
)

View File

@ -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" }

View File

@ -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
}

View File

@ -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)

View File

@ -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
}