Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release0.8 #39

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 0.8

- Update to Kotlin 2.1.0
- Added: w(TAG, Throwable) for logging exceptions as warnings w/o providing a message

## 0.7

- Update to Kotlin 2.0.20
2 changes: 1 addition & 1 deletion build-plugins/src/main/kotlin/root.publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ plugins {

allprojects {
group = "de.halfbit"
version = "0.7"
version = "0.8"
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
agp = "8.7.2"
kotlin = "2.0.21"
agp = "8.7.3"
kotlin = "2.1.0"

android-minSdk = "24"
android-compileSdk = "34"
920 changes: 499 additions & 421 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion logger/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
11 changes: 11 additions & 0 deletions logger/src/appleMain/kotlin/de/halfbit/logger/LogTag.apple.kt
Original file line number Diff line number Diff line change
@@ -15,8 +15,14 @@ import platform.Foundation.NSThread
public fun autoTag(loggableLevel: LoggableLevel = Everything): LogTag =
namedTag(name = detectTag(), loggableLevel = loggableLevel)

private const val ENABLE_DEBUG_TRACES = false

private fun detectTag(): String {
val callstack = NSThread.callStackSymbols
if (ENABLE_DEBUG_TRACES) {
println("===============================")
println(callstack.joinToString("\n"))
}
val element = callstack.getOrNull(3)?.toString() ?: throwAutoTagFailed()
return element.cleanClassName
}
@@ -30,6 +36,7 @@ private val String.cleanClassName: String

var cleanClassName =
substring(0, endIndex)
.removeSuffix(".<init>")
.removeSuffix(".Companion")

if (cleanClassName.endsWith(".\$init_global")) {
@@ -43,6 +50,10 @@ private val String.cleanClassName: String
cleanClassName = cleanClassName.removePackage()
}

if (ENABLE_DEBUG_TRACES) {
println("$cleanClassName <<<< $this")
}

return cleanClassName
}

12 changes: 12 additions & 0 deletions logger/src/commonMain/kotlin/de/halfbit/logger/log.kt
Original file line number Diff line number Diff line change
@@ -55,6 +55,18 @@ public inline fun w(tag: LogTag, err: Throwable, getMessage: () -> String) {
}
}

public fun w(tag: String, err: Throwable) {
if (currentLogger.loggableLevel.weight <= Warning.weight) {
log(Warning, tag, null, err)
}
}

public fun w(tag: LogTag, err: Throwable) {
if (tag.loggableLevel.weight <= Warning.weight) {
w(tag.name, err)
}
}

public inline fun e(tag: String, getMessage: () -> String) {
if (currentLogger.loggableLevel.weight <= Error.weight) {
log(Error, tag, getMessage(), null)
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class LogExceptionsTest {
private lateinit var memoryRingSink: MemoryRingSink

@Test
fun logException() {
fun logExceptionAsError() {
// given
initializeLogger {
memoryRingSink = registerMemoryRingSink(LogPrinter.Default)
@@ -41,4 +41,31 @@ class LogExceptionsTest {

}
}

@Test
fun logExceptionAsWarning() {
// given
initializeLogger {
memoryRingSink = registerMemoryRingSink(LogPrinter.Default)
getClockNow = { Instant.parse("2024-06-18T23:40:57.120Z") }
}

// when
w(TAG, Exception()) { "Warning message" }

// then
val stackTrace = memoryRingSink.getLogEntries().first().lines()
assertTrue(stackTrace.size > 3)

val actualMessage = stackTrace[0]
val expectedMessage = "23:40:57.120 .... LogExceptionsTest W Warning message"
assertEquals(expectedMessage, actualMessage)

val actualException = stackTrace[1]
assertTrue("Cannot find exception in: $actualException") {
actualException.contains("Exception") ||
actualException.contains("captureStack") // js, wasmJs (firefox)

}
}
}
2 changes: 1 addition & 1 deletion sample-apps/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
2 changes: 1 addition & 1 deletion sample-apps/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {