generated from rnentjes/kotlin-server-web-empty
Add logging functionality and Maven publishing setup
Added Logger class with various log levels to `commonMain`. Integrated `maven-publish` and `signing` plugins in `build.gradle.kts` to facilitate publishing artifacts to the Maven repository with proper credentials and metadata. Removed `gradle.properties` and updated `.gitignore` accordingly.
This commit is contained in:
52
src/commonMain/kotlin/nl/astraeus/logger/Logger.kt
Normal file
52
src/commonMain/kotlin/nl/astraeus/logger/Logger.kt
Normal file
@@ -0,0 +1,52 @@
|
||||
package nl.astraeus.logger
|
||||
|
||||
enum class LogLevel {
|
||||
TRACE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
FATAL
|
||||
}
|
||||
|
||||
class Logger(
|
||||
var level: LogLevel = LogLevel.INFO
|
||||
) {
|
||||
|
||||
fun trace(message: () -> String?) {
|
||||
if (level.ordinal <= LogLevel.TRACE.ordinal) {
|
||||
println("TRACE: ${message()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun debug(message: () -> String?) {
|
||||
if (level.ordinal <= LogLevel.DEBUG.ordinal) {
|
||||
println("DEBUG: ${message()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun info(message: () -> String?) {
|
||||
if (level.ordinal <= LogLevel.INFO.ordinal) {
|
||||
println("INFO: ${message()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun warn(e: Throwable? = null, message: () -> String?) {
|
||||
if (level.ordinal <= LogLevel.WARN.ordinal) {
|
||||
println("WARN: ${message()}")
|
||||
e?.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun error(e: Throwable? = null, message: () -> String?) {
|
||||
if (level.ordinal <= LogLevel.ERROR.ordinal) {
|
||||
println("ERROR: ${message()}")
|
||||
e?.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun fatal(e: Throwable, message: () -> String?) {
|
||||
println("FATAL: ${message()}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user