Version. 1.0.0

This commit is contained in:
2024-10-27 10:51:16 +01:00
parent 049347b2d2
commit 4594476416
6 changed files with 110 additions and 50 deletions

View File

@@ -1,6 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kotlin-simple-logging-js-1.0.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kotlin-simple-logging-js-1.0.0-SNAPSHOT.jar" />
<root id="archive" name="kotlin-simple-logging-js-1.0.0-SNAPSHOT.jar">
<element id="module-output" name="kotlin-simple-logging.jsMain" />
</root>
</artifact>
</component>

View File

@@ -1,6 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kotlin-simple-logging-jvm-1.0.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kotlin-simple-logging-jvm-1.0.0-SNAPSHOT.jar" />
<root id="archive" name="kotlin-simple-logging-jvm-1.0.0-SNAPSHOT.jar">
<element id="module-output" name="kotlin-simple-logging.jvmMain" />
</root>
</artifact>
</component>

View File

@@ -8,15 +8,19 @@ plugins {
}
group = "nl.astraeus"
version = "1.0.0-SNAPSHOT"
version = "1.0.0"
repositories {
mavenCentral()
}
kotlin {
jvm {}
js {}
jvm {
withJava()
}
js {
browser {}
}
sourceSets {
val commonMain by getting
val jvmMain by getting
@@ -24,19 +28,33 @@ kotlin {
}
}
extra["PUBLISH_GROUP_ID"] = group
extra["PUBLISH_VERSION"] = version
extra["PUBLISH_ARTIFACT_ID"] = name
// Stub secrets to let the project sync and build without the publication values set up
val signingKeyId: String? by project
val signingPassword: String? by project
val signingSecretKeyRingFile: String? by project
extra["signing.keyId"] = signingKeyId
extra["signing.password"] = signingPassword
extra["signing.secretKeyRingFile"] = signingSecretKeyRingFile
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
publishing {
repositories {
mavenLocal()
maven {
name = "gitea"
setUrl("https://gitea.astraeus.nl/api/packages/rnentjes/maven")
credentials() {
val giteaUsername: kotlin.String? by project
val giteaPassword: kotlin.String? by project
credentials {
val giteaUsername: String? by project
val giteaPassword: String? by project
username = giteaUsername
password = giteaPassword
@@ -51,9 +69,9 @@ publishing {
// Provide artifacts information requited by Maven Central
pom {
name.set("kotlin-komponent")
description.set("Kotlin komponent")
url.set("https://github.com/rnentjes/komponent")
name.set("kotlin-simple-logging")
description.set("Kotlin simple logging")
url.set("https://gitea.astraeus.nl/rnentjes/kotlin-simple-logging")
licenses {
license {
@@ -69,7 +87,7 @@ publishing {
}
}
scm {
url.set("https://github.com/rnentjes/komponent")
url.set("https://gitea.astraeus.nl/rnentjes/kotlin-simple-logging.git")
}
}
}
@@ -78,3 +96,7 @@ publishing {
signing {
sign(publishing.publications)
}
tasks.withType<PublishToMavenRepository> {
dependsOn(tasks.withType<Sign>())
}

View File

@@ -1,52 +1,68 @@
package nl.astraeus.logger
enum class LogLevel {
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL
enum class LogLevel(
val label: String
) {
TRACE("Trace"),
DEBUG("Debug"),
INFO(" Info"),
WARN(" Warn"),
ERROR("Error"),
FATAL("Fatal");
}
expect fun getTimestamp(): String
expect fun getCurrentThread(): String?
expect fun getCaller(): String?
class Logger(
var level: LogLevel = LogLevel.INFO
var level: LogLevel = LogLevel.INFO,
val name: String = ""
) {
fun trace(message: () -> String?) {
if (level.ordinal <= LogLevel.TRACE.ordinal) {
println("TRACE: ${message()}")
}
}
fun trace(message: () -> String) = log(LogLevel.TRACE, null, message)
fun debug(message: () -> String) = log(LogLevel.DEBUG, null, message)
fun info(message: () -> String) = log(LogLevel.INFO, null, message)
fun warn(message: () -> String) = log(LogLevel.WARN, null, message)
fun error(message: () -> String) = log(LogLevel.ERROR, null, message)
fun fatal(message: () -> String) = log(LogLevel.FATAL, null, message)
fun debug(message: () -> String?) {
if (level.ordinal <= LogLevel.DEBUG.ordinal) {
println("DEBUG: ${message()}")
}
}
fun trace(thrown: Throwable, message: () -> String) = log(LogLevel.TRACE, thrown, message)
fun debug(thrown: Throwable, message: () -> String) = log(LogLevel.DEBUG, thrown, message)
fun info(thrown: Throwable, message: () -> String) = log(LogLevel.INFO, thrown, message)
fun warn(thrown: Throwable, message: () -> String) = log(LogLevel.WARN, thrown, message)
fun error(thrown: Throwable, message: () -> String) = log(LogLevel.ERROR, thrown, message)
fun fatal(thrown: Throwable, message: () -> String) = log(LogLevel.FATAL, thrown, message)
fun info(message: () -> String?) {
if (level.ordinal <= LogLevel.INFO.ordinal) {
println("INFO: ${message()}")
}
}
private fun log(
level: LogLevel,
thrown: Throwable? = null,
message: () -> String
) {
if (level.ordinal >= this.level.ordinal) {
val timestamp: String = getTimestamp()
val thread: String? = getCurrentThread()
val caller: String? = getCaller()
fun warn(e: Throwable? = null, message: () -> String?) {
if (level.ordinal <= LogLevel.WARN.ordinal) {
println("WARN: ${message()}")
e?.printStackTrace()
}
}
val logEntry = StringBuilder()
fun error(e: Throwable? = null, message: () -> String?) {
if (level.ordinal <= LogLevel.ERROR.ordinal) {
println("ERROR: ${message()}")
e?.printStackTrace()
logEntry.append(timestamp)
logEntry.append(" - ")
logEntry.append(level.name)
logEntry.append(" - ")
if (thread != null) {
logEntry.append(thread)
logEntry.append(" - ")
}
if (caller != null) {
logEntry.append(caller)
logEntry.append(" - ")
}
logEntry.append(message())
fun fatal(e: Throwable, message: () -> String?) {
println("FATAL: ${message()}")
e.printStackTrace()
println(logEntry)
thrown?.printStackTrace()
}
}
}

View File

@@ -0,0 +1,9 @@
package nl.astraeus.logger
import kotlin.js.Date
actual fun getTimestamp(): String = Date().toISOString()
actual fun getCurrentThread(): String? = null
actual fun getCaller(): String? = null

View File

@@ -0,0 +1,9 @@
package nl.astraeus.logger
import java.util.*
actual fun getTimestamp(): String = Date().toString()
actual fun getCurrentThread(): String? = Thread.currentThread().name
actual fun getCaller(): String? = Throwable().stackTrace[2].toString()