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"> <component name="ArtifactManager">
<artifact type="jar" name="kotlin-simple-logging-js-1.0.0-SNAPSHOT"> <artifact type="jar" name="kotlin-simple-logging-js-1.0.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path> <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> </artifact>
</component> </component>

View File

@@ -1,6 +1,8 @@
<component name="ArtifactManager"> <component name="ArtifactManager">
<artifact type="jar" name="kotlin-simple-logging-jvm-1.0.0-SNAPSHOT"> <artifact type="jar" name="kotlin-simple-logging-jvm-1.0.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path> <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> </artifact>
</component> </component>

View File

@@ -8,15 +8,19 @@ plugins {
} }
group = "nl.astraeus" group = "nl.astraeus"
version = "1.0.0-SNAPSHOT" version = "1.0.0"
repositories { repositories {
mavenCentral() mavenCentral()
} }
kotlin { kotlin {
jvm {} jvm {
js {} withJava()
}
js {
browser {}
}
sourceSets { sourceSets {
val commonMain by getting val commonMain by getting
val jvmMain 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) { val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc") archiveClassifier.set("javadoc")
} }
publishing { publishing {
repositories { repositories {
mavenLocal()
maven { maven {
name = "gitea" name = "gitea"
setUrl("https://gitea.astraeus.nl/api/packages/rnentjes/maven") setUrl("https://gitea.astraeus.nl/api/packages/rnentjes/maven")
credentials() { credentials {
val giteaUsername: kotlin.String? by project val giteaUsername: String? by project
val giteaPassword: kotlin.String? by project val giteaPassword: String? by project
username = giteaUsername username = giteaUsername
password = giteaPassword password = giteaPassword
@@ -51,9 +69,9 @@ publishing {
// Provide artifacts information requited by Maven Central // Provide artifacts information requited by Maven Central
pom { pom {
name.set("kotlin-komponent") name.set("kotlin-simple-logging")
description.set("Kotlin komponent") description.set("Kotlin simple logging")
url.set("https://github.com/rnentjes/komponent") url.set("https://gitea.astraeus.nl/rnentjes/kotlin-simple-logging")
licenses { licenses {
license { license {
@@ -69,7 +87,7 @@ publishing {
} }
} }
scm { 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 { signing {
sign(publishing.publications) sign(publishing.publications)
} }
tasks.withType<PublishToMavenRepository> {
dependsOn(tasks.withType<Sign>())
}

View File

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