Archived
1
0
Fork 0
This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
uranos/blokk-api/src/main/kotlin/space/blokk/logging/Logger.kt
Moritz Ruth ffe2349884
Update everything to 1.16.4
this took me about 12 hours. it's 1 am
2020-12-21 01:05:28 +01:00

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