-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- removed KotlinX.DateTime & moved from Instant to Timestamp. - WASM support.
- Loading branch information
1 parent
8b826a9
commit ba5de82
Showing
22 changed files
with
141 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ plugins { | |
|
||
allprojects { | ||
group = "org.kodein.log" | ||
version = "0.19.0" | ||
version = "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.kodein.log | ||
|
||
import kotlin.jvm.JvmInline | ||
|
||
@JvmInline | ||
public value class Timestamp(public val msecSinceEpoch: ULong) | ||
|
||
public expect fun now(): Timestamp | ||
|
||
public expect fun Timestamp.toLocalString(): String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
canard/src/datetimeMain/kotlin/org/kodein/log/instantDateTime.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
canard/src/embeddedNativeMain/kotlin/org/kodein/log/instantEmbedded.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.kodein.log | ||
|
||
import kotlin.js.Date | ||
|
||
|
||
public actual fun now(): Timestamp = Timestamp(Date.now().toULong()) | ||
|
||
@Suppress("LocalVariableName") | ||
public actual fun Timestamp.toLocalString(): String = Date(msecSinceEpoch.toDouble()).let { | ||
val Y = it.getFullYear().toString() | ||
val M = it.getMonth().inc().toString().padStart(2, '0') | ||
val D = it.getDate().toString().padStart(2, '0') | ||
val h = it.getHours().toString().padStart(2, '0') | ||
val m = it.getMinutes().toString().padStart(2, '0') | ||
val s = it.getSeconds().toString().padStart(2, '0') | ||
val ss = it.getMilliseconds().toString().padStart(3, '0') | ||
|
||
"$Y/$M/$D $h:$m:$s:$ss" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.kodein.log | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
|
||
public actual fun now(): Timestamp = Timestamp(System.currentTimeMillis().toULong()) | ||
|
||
private val dtf = SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS") | ||
|
||
public actual fun Timestamp.toLocalString(): String = dtf.format(Date(msecSinceEpoch.toLong())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
canard/src/nativeMain/kotlin/org/kodein/log/timestampNative.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.kodein.log | ||
|
||
import kotlinx.cinterop.* | ||
import platform.posix.* | ||
|
||
|
||
@OptIn(UnsafeNumber::class, ExperimentalForeignApi::class) | ||
public actual fun now(): Timestamp { | ||
memScoped { | ||
val spec = alloc<timespec>() | ||
clock_gettime(CLOCK_REALTIME.convert(), spec.ptr) | ||
return Timestamp(spec.tv_sec.toULong() * 1_000u + spec.tv_nsec.toULong() / 1_000_000u) | ||
} | ||
} | ||
|
||
@OptIn(UnsafeNumber::class, ExperimentalForeignApi::class) | ||
public actual fun Timestamp.toLocalString(): String { | ||
memScoped { | ||
val ms = msecSinceEpoch % 1_000u | ||
val sec = alloc<time_tVar>() | ||
sec.value = (msecSinceEpoch / 1_000u).convert() | ||
val info = localtime(sec.ptr) | ||
|
||
val chars = allocArray<ByteVar>(32) | ||
strftime(chars, 31.convert(), "%Y-%m-%dT%H:%M:%S", info) | ||
|
||
return chars.toKString() + "." + ms.toString().padStart(3, '0') | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
canard/src/wasmMain/kotlin/org/kodein/log/frontend/defaultNative.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.kodein.log.frontend | ||
|
||
import org.kodein.log.LogFrontend | ||
|
||
public actual val defaultLogFrontend: LogFrontend = printFrontend |
7 changes: 7 additions & 0 deletions
7
canard/src/wasmMain/kotlin/org/kodein/log/frontend/printStackTraceWasm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.kodein.log.frontend | ||
|
||
|
||
internal actual fun errPrintln(msg: String) { println(msg) } | ||
|
||
internal actual fun Throwable.getStackTraceStrings(): Array<String> = | ||
arrayOf("Stack traces are currently not supported in WASM") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.kodein.log | ||
|
||
import kotlin.reflect.KClass | ||
|
||
public actual val KClass<*>.platformSimpleName: String get() = simpleName ?: "?" | ||
|
||
public actual val KClass<*>.platformPackageName: String get() = "kotlin.wasm" |
Oops, something went wrong.