Skip to content

Commit

Permalink
add default console log impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy committed Jan 29, 2025
1 parent 50f4c2d commit a5d7890
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Consts {
const val releaseGroup = "com.piasy"
const val releaseName = "kmp-xlog"
const val releaseVersion = "1.2.1"
const val releaseVersion = "1.2.2"

val androidNS = "$releaseGroup.${releaseName.replace('-', '_')}"
}
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ ndk = "21.3.6528147"
compileSdk = "35"
minSdk = "21"
targetSdk = "35"
agp = "8.7.2"
agp = "8.8.0"
kotlin = "2.1.0"
mockk = "1.13.13"
compose = "1.7.5"
mockk = "1.13.16"
compose = "1.7.6"

[libraries]
kotlin-stdlib-js = { module = "org.jetbrains.kotlin:kotlin-stdlib-js", version.ref = "kotlin" }
kotlinx-datetime = "org.jetbrains.kotlinx:kotlinx-datetime:0.6.1"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
Expand All @@ -20,7 +21,7 @@ androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", versi
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }
androidx-activity-compose = "androidx.activity:activity-compose:1.9.3"
androidx-activity-compose = "androidx.activity:activity-compose:1.10.0"

[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 16 22:27:43 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
6 changes: 6 additions & 0 deletions kmp-xlog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ kotlin {
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
}

commonMain {
dependencies {
implementation(libs.kotlinx.datetime)
}
}

androidUnitTest {
dependencies {
implementation(libs.kotlin.test)
Expand Down
21 changes: 17 additions & 4 deletions kmp-xlog/src/commonMain/kotlin/com/piasy/kmp/xlog/Logging.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piasy.kmp.xlog

import kotlinx.datetime.Clock
import kotlin.math.min

/**
Expand All @@ -11,27 +12,39 @@ object Logging {
const val LEVEL_ERROR = 4

internal const val LINE_LENGTH = 4000
private var impl: LoggingImpl? = null
private var impl: LoggingImpl = object : LoggingImpl {
override fun debug(tag: String, content: String) {
println("${Clock.System.now().toEpochMilliseconds()} D $tag $content")
}

override fun info(tag: String, content: String) {
println("${Clock.System.now().toEpochMilliseconds()} I $tag $content")
}

override fun error(tag: String, content: String) {
println("${Clock.System.now().toEpochMilliseconds()} E $tag $content")
}
}

internal fun init(impl: LoggingImpl) {
this.impl = impl
}

fun debug(tag: String, content: String) {
log(tag, content) { t, c ->
impl?.debug(t, c)
impl.debug(t, c)
}
}

fun info(tag: String, content: String) {
log(tag, content) { t, c ->
impl?.info(t, c)
impl.info(t, c)
}
}

fun error(tag: String, content: String) {
log(tag, content) { t, c ->
impl?.error(t, c)
impl.error(t, c)
}
}

Expand Down

0 comments on commit a5d7890

Please sign in to comment.