Skip to content

Commit

Permalink
Add khronicle logger
Browse files Browse the repository at this point in the history
  • Loading branch information
cedrickcooke committed Sep 5, 2024
1 parent e1b41bc commit a1b189b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kotlin = "2.0.20"

[libraries]
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
khronicle-core = { module = "com.juul.khronicle:khronicle-core", version = "0.3.0" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
Expand Down
24 changes: 24 additions & 0 deletions logging-khronicle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
kotlin("multiplatform")
id("org.jmailen.kotlinter")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish")
}

kotlin {
explicitApi()

js {
browser()
binaries.library()
}

sourceSets {
val commonMain by getting {
dependencies {
api(project(":core"))
api(libs.khronicle.core)
}
}
}
}
6 changes: 6 additions & 0 deletions logging-khronicle/src/jsMain/kotlin/Event.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.juul.indexeddb.logs

import com.juul.khronicle.Key
import org.w3c.dom.events.Event

public object Event : Key<Event>
25 changes: 25 additions & 0 deletions logging-khronicle/src/jsMain/kotlin/KhronicleLogger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.juul.indexeddb.logs

import com.juul.khronicle.Log
import com.juul.khronicle.LogLevel
import org.w3c.dom.events.Event as JsEvent

public object KhronicleLogger : Logger {

override fun log(type: Type, event: JsEvent?, message: () -> String) {
val level = when (event?.type) {
"error", "blocked" -> LogLevel.Error
else -> when (type) {
Type.Database -> LogLevel.Info
Type.Transaction -> LogLevel.Debug
else -> LogLevel.Verbose
}
}
Log.dynamic(level = level, tag = "IndexedDB/$type") { metadata ->
if (event != null) {
metadata[Event] = event
}
message()
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pluginManagement {
include(
"core",
"external",
"logging-khronicle",
)

0 comments on commit a1b189b

Please sign in to comment.