Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://github.com/Kotlin/multiplatform-library-template/blob/main/.github/workflows/gradle.yml
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: kmp-xlog build and test.
name: CI

on:
push:
Expand All @@ -19,22 +19,20 @@ jobs:
fail-fast: false
matrix:
include:
- cmd: "${GITHUB_WORKSPACE}/gradlew :kmp-xlog:testDebugUnitTest"
os: macos-latest
- cmd: "${GITHUB_WORKSPACE}/gradlew :example:androidApp:assembleDebug"
os: macos-latest
- cmd: "${GITHUB_WORKSPACE}/scripts/build_apple.sh && ${GITHUB_WORKSPACE}/gradlew runKmp_xlogDebugExecutableMacosX64"
os: macos-latest
- os: macos-latest
cmd: "./gradlew :kmp-xlog:testDebugUnitTest"
- os: macos-latest
cmd: "./gradlew :example:androidApp:assembleDebug"
- os: macos-latest
dep: "brew update && brew install xcodegen"
- cmd: "${GITHUB_WORKSPACE}/scripts/build_xlog_linux.sh && ${GITHUB_WORKSPACE}/gradlew runKmp_xlogDebugExecutableLinuxX64"
os: ubuntu-22.04
cmd: "./scripts/build_apple.sh && ./gradlew runKmp_xlogDebugExecutableMacosX64 && ./scripts/build_mac_demo.sh && ./scripts/build_ios_demo.sh"
- os: ubuntu-22.04
dep: "sudo apt-get update && sudo apt-get install zlib1g-dev"
- cmd: "%GITHUB_WORKSPACE%\\gradlew runKmp_xlogDebugExecutableMingwX64"
os: windows-latest
- cmd: "${GITHUB_WORKSPACE}/gradlew :example:shared:jsBrowserDistribution"
os: macos-latest
- cmd: "${GITHUB_WORKSPACE}/gradlew :example:shared:wasmJsBrowserDistribution"
os: macos-latest
cmd: "./scripts/build_xlog_linux.sh && ./gradlew runKmp_xlogDebugExecutableLinuxX64"
- os: windows-latest
cmd: "./gradlew runKmp_xlogDebugExecutableMingwX64"
- os: macos-latest
cmd: "./gradlew :example:shared:jsBrowserDistribution"
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -54,10 +52,8 @@ jobs:
cache: 'gradle'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- if: ${{ matrix.dep }}
- name: Install deps
if: ${{ matrix.dep }}
run: ${{ matrix.dep }}
- if: ${{ matrix.os == 'windows-latest' }}
shell: cmd
run: ${{ matrix.cmd }}
- if: ${{ matrix.os != 'windows-latest' }}
- name: Run it
run: ${{ matrix.cmd }}
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

KMP wrapper for [tencent mars xlog](https://github.com/Tencent/mars).

![Maven Central Version](https://img.shields.io/maven-central/v/com.piasy/kmp-xlog) ![Main branch status](https://github.com/HackWebRTC/kmp-xlog/actions/workflows/test_and_run_demo.yaml/badge.svg?branch=main)
![Maven Central Version](https://img.shields.io/maven-central/v/com.piasy/kmp-xlog) ![Main branch status](https://github.com/HackWebRTC/kmp-xlog/actions/workflows/ci.yaml/badge.svg?branch=main)

## Supported platforms

| Platform | 🛠Builds🛠 + 🔬Tests🔬 |
| :----------------: | :------------------: |
| `JVM` 17 | 🚀 |
| `JS` (Chrome) | 🚀 |
| `WasmJS` (Chrome) | 🚀 |
| `Android` | 🚀 |
| `iOS` | 🚀 |
| `macOS` | 🚀 |
Expand Down Expand Up @@ -128,12 +127,6 @@ pod install
./gradlew :example:shared:jsBrowserRun
```

### WASM JS

```bash
./gradlew :example:shared:wasmJsBrowserRun
```

### Linux

Install deps: `zlib1g-dev`.
Expand Down
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.3.6"
const val releaseVersion = "1.4.0"

val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
}
2 changes: 1 addition & 1 deletion example/macApp/macApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)viewDidLoad {

[self.view addSubview:self.label];

[Kmp_xlogLoggingKt initializeMarsXLogLevel:1 namePrefix:@"test" logToConsole:YES];
[Kmp_xlogLoggingKt initializeMarsXLogLevel:1 namePrefix:@"test" debugLog:YES];
[[Kmp_xlogLogging logging] infoTag:@"XXPXX" content:[NSString stringWithFormat:@"greeting from %@", [self getSystemVersion]]];
[[Kmp_xlogLogging logging] errorTag:@"XXPXX" content:@"flush"];
}
Expand Down
13 changes: 0 additions & 13 deletions example/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kmp)

Expand Down Expand Up @@ -43,12 +41,6 @@ kotlin {
}
binaries.executable()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
}
binaries.executable()
}

listOf(linuxX64(), mingwX64()).forEach {
it.binaries {
Expand Down Expand Up @@ -77,11 +69,6 @@ kotlin {
mingwX64Main {
dependsOn(cppCommon)
}
wasmJsMain {
dependencies {
implementation(libs.kotlinx.browser)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class JsPlatform : Platform {
actual fun getPlatform(): Platform = JsPlatform()

fun main() {
initializeConsoleLog()
initializeConsoleLog(true)

document.getElementById("text")?.innerHTML = Greeting().greeting()
}

This file was deleted.

11 changes: 0 additions & 11 deletions example/shared/src/wasmJsMain/resources/index.html

This file was deleted.

8 changes: 3 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ compileSdk = "35"
minSdk = "21"
targetSdk = "35"
agp = "8.7.3"
kotlin = "2.1.0"
kotlin = "2.1.10"
mockk = "1.13.16"
compose = "1.7.6"
kotlinxBrowser = "0.3"
compose = "1.7.8"

[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" }
kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinxBrowser" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
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.10.0"
androidx-activity-compose = "androidx.activity:activity-compose:1.10.1"

[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
Expand Down
8 changes: 3 additions & 5 deletions kmp-xlog-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kmp)
Expand All @@ -18,11 +17,10 @@ kotlin {
macosArm64()
macosX64()

@OptIn(ExperimentalWasmDsl::class)
listOf(js(IR), wasmJs()).forEach {
it.browser {
js(IR) {
browser {
}
it.binaries.executable()
binaries.executable()
}

linuxX64()
Expand Down
105 changes: 54 additions & 51 deletions kmp-xlog-api/src/commonMain/kotlin/com/piasy/kmp/xlog/Logging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,76 @@ import kotlin.math.min
* Created by Piasy{github.com/Piasy} on 2022/11/16.
*/
object Logging {
const val LEVEL_DEBUG = 1
const val LEVEL_INFO = 2
const val LEVEL_ERROR = 4
const val LEVEL_DEBUG = 1
const val LEVEL_INFO = 2
const val LEVEL_ERROR = 4

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

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

override fun error(tag: String, content: String) {
println("${Clock.System.now().toEpochMilliseconds()} E $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")
}
}
}

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

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

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

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

private fun log(
tag: String,
content: String,
logFunc: (
tag: String,
content: String
) -> Unit
) {
// MarsXLog limit single log length to 4096
if (content.length <= LINE_LENGTH) {
logFunc(tag, content)
} else {
var write = 0
while (write < content.length) {
val endIndex = min(content.length, write + LINE_LENGTH)
logFunc(tag, content.substring(write, endIndex))
write = endIndex
}
private fun log(
tag: String,
content: String,
logFunc: (
tag: String,
content: String
) -> Unit
) {
// MarsXLog limit single log length to 4096
if (content.length <= LINE_LENGTH) {
logFunc(tag, content)
} else {
var write = 0
while (write < content.length) {
val endIndex = min(content.length, write + LINE_LENGTH)
logFunc(tag, content.substring(write, endIndex))
write = endIndex
}
}
}
}
}

interface LoggingImpl {
fun debug(tag: String, content: String)
fun debug(): Boolean
fun debug(tag: String, content: String)

fun info(tag: String, content: String)
fun info(tag: String, content: String)

fun error(tag: String, content: String)
fun error(tag: String, content: String)
}

This file was deleted.

7 changes: 1 addition & 6 deletions kmp-xlog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ kotlin {
extraSpecAttributes["libraries"] = "'z'"
extraSpecAttributes["framework"] = "'SystemConfiguration'"
framework {
export(project(":kmp-xlog-api"))
baseName = "kmp_xlog"
isStatic = true
}
Expand All @@ -53,12 +54,6 @@ kotlin {
}
binaries.executable()
}
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
wasmJs {
browser {
}
binaries.executable()
}

linuxX64 {
compilations.getByName("main") {
Expand Down
Loading
Loading