53 lines
1.5 KiB
Kotlin
53 lines
1.5 KiB
Kotlin
package space.blokk.logging
|
|
|
|
import space.blokk.Blokk
|
|
|
|
class Logger(val name: String, private val printThreadName: Boolean = true) {
|
|
fun log(level: Level, message: String, throwable: Throwable? = null) =
|
|
Blokk.loggingOutputProvider.log(printThreadName, name, level, message, throwable)
|
|
|
|
fun error(msg: String, t: Throwable) {
|
|
if (Level.ERROR.isEnabled) {
|
|
error(msg)
|
|
t.printStackTrace()
|
|
}
|
|
}
|
|
|
|
infix fun error(message: String) = log(Level.ERROR, message, null)
|
|
infix fun info(message: String) = log(Level.INFO, message, null)
|
|
infix fun warn(message: String) = log(Level.WARN, message, null)
|
|
infix fun debug(message: String) = log(Level.DEBUG, message, null)
|
|
infix fun trace(message: String) = log(Level.TRACE, message, null)
|
|
|
|
inline infix fun error(fn: () -> String) {
|
|
if (Level.ERROR.isEnabled) error(fn())
|
|
}
|
|
|
|
inline infix fun info(fn: () -> String) {
|
|
if (Level.INFO.isEnabled) info(fn())
|
|
}
|
|
|
|
inline infix fun warn(fn: () -> String) {
|
|
if (Level.WARN.isEnabled) warn(fn())
|
|
}
|
|
|
|
inline infix fun debug(fn: () -> String) {
|
|
if (Level.DEBUG.isEnabled) debug(fn())
|
|
}
|
|
|
|
inline infix fun trace(fn: () -> String) {
|
|
if (Level.TRACE.isEnabled) trace(fn())
|
|
}
|
|
|
|
enum class Level {
|
|
TRACE,
|
|
DEBUG,
|
|
INFO,
|
|
WARN,
|
|
ERROR;
|
|
|
|
fun isGreaterOrEqualThan(level: Level) = ordinal >= level.ordinal
|
|
|
|
val isEnabled get() = isGreaterOrEqualThan(Blokk.minimumLogLevel)
|
|
}
|
|
}
|