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:
2024-10-26 15:26:21 +02:00
parent fd81c0fcb4
commit 63625873be
7 changed files with 116 additions and 43 deletions

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