Compare commits

...

88 Commits

Author SHA1 Message Date
663395ccbe update dependencies, update changelog, replace KSLoggerDefaultPlatformLoggerLambda in nativeMain 2024-05-12 16:48:47 +06:00
ecd2b08c69 start 1.3.4 2024-05-12 16:42:35 +06:00
f5e50d00a2 Merge pull request #73 from InsanusMokrassar/1.3.3
1.3.3
2024-03-15 13:39:16 +06:00
a1784dc6af Update CHANGELOG.md 2024-03-15 13:21:16 +06:00
4d6410c870 Update gradle-wrapper.properties 2024-03-15 13:19:40 +06:00
3a4035f1a6 Update libs.versions.toml 2024-03-15 13:16:49 +06:00
86bf9468ba Update gradle.properties 2024-03-15 13:14:00 +06:00
24adeef67b Merge pull request #67 from InsanusMokrassar/1.3.2
1.3.2
2024-01-17 23:33:45 +06:00
4823df5c6f update gradle wrapper 2024-01-16 12:48:29 +06:00
2d397e9b12 update dependencies 2024-01-16 12:47:07 +06:00
37a0fceb56 start 1.3.2 2024-01-16 12:46:07 +06:00
0860d6cacc update artifacts to be published in nexus 2023-12-05 19:41:15 +06:00
d9863ded5a Merge pull request #62 from InsanusMokrassar/1.3.1
1.3.1
2023-11-24 16:44:52 +06:00
48a265e3d5 update dependencies 2023-11-24 16:38:30 +06:00
30cdbea2c9 start 1.3.1 2023-11-24 16:37:15 +06:00
b19639e8a1 Merge branch '1.3.0' (fix of js assert accordance) 2023-11-18 18:08:38 +06:00
447e4fe5ac hotfix of js assert accordance 2023-11-18 18:08:19 +06:00
30d82ebda6 Merge pull request #59 from InsanusMokrassar/1.3.0
1.3.0
2023-11-18 18:04:06 +06:00
0b7b408b06 update changelog 2023-11-18 17:59:45 +06:00
ea43501a03 migration onto 1.3.0 2023-11-18 17:55:50 +06:00
0348756729 a lot of changes and improvements 2023-11-18 17:55:19 +06:00
81b32b0119 add a lot of kdocs 2023-11-18 17:15:23 +06:00
7a8bd035f5 add trace level 2023-11-18 16:18:45 +06:00
34a7c9624d start 1.2.5 2023-11-18 16:17:42 +06:00
fb0f61bb15 Merge pull request #55 from InsanusMokrassar/1.2.4
1.2.4
2023-11-02 18:16:47 +06:00
48eeb6660e fill changelog 2023-11-02 18:14:14 +06:00
ff14fd5e7c fixes of publication? 2023-11-02 18:06:55 +06:00
aa7bd6179a update gradle versions and publication scripts 2023-11-02 17:59:22 +06:00
ef72365505 start 1.2.4 2023-11-02 17:29:46 +06:00
c0a10436be Merge pull request #54 from InsanusMokrassar/1.2.3
1.2.3
2023-11-01 23:43:57 +06:00
a3170786a7 update dependencies 2023-11-01 23:40:32 +06:00
d60e35f1e9 start 1.2.3 2023-11-01 23:39:39 +06:00
bed00407fb downgrade version of gradle 2023-10-23 13:39:10 +06:00
f326d9070a second try to fix publish issues 2023-10-23 02:12:38 +06:00
b4c454141e add crutch for publishing of artifacts 2023-10-23 02:05:05 +06:00
1a589c675e Merge pull request #47 from InsanusMokrassar/1.2.2
1.2.2
2023-10-23 01:38:51 +06:00
d25a73df3d remove unnecessary targets 2023-10-23 01:37:41 +06:00
333cb690a1 get back version of kslog 2023-09-22 01:52:15 +06:00
a3e6ccf973 get back build.gradle 2023-09-22 01:46:05 +06:00
9ce62e13f5 migrate onto build.gradle.kts 2023-09-20 22:27:06 +06:00
e88df8db99 update github workflows java toolchain versions 2023-09-20 21:45:39 +06:00
8613f350e3 update of gradle wrapper and publishing scripts 2023-09-20 21:39:01 +06:00
7fbf80a52a start 1.2.2 2023-09-20 20:04:27 +06:00
00da37e060 Merge pull request #45 from InsanusMokrassar/1.2.1
1.2.1
2023-09-06 19:05:58 +06:00
a779791a00 update dependencies 2023-09-06 19:05:12 +06:00
03cc000306 start 1.2.1 2023-09-06 19:02:59 +06:00
875d2d723e Merge pull request #41 from InsanusMokrassar/1.2.0
1.2.0
2023-07-28 12:21:55 +06:00
01722311e6 update kotlin and add versions plugin 2023-07-28 12:15:01 +06:00
9b994de857 start 1.2.0 2023-07-28 12:15:01 +06:00
a170bbaa5c Merge pull request #39 from InsanusMokrassar/1.1.2
1.1.2
2023-07-28 12:14:28 +06:00
7b8d72e9c0 update test dependencies 2023-06-19 22:47:41 +06:00
0237ec56c5 update dependencies 2023-06-19 22:46:45 +06:00
bef9e0c550 start 1.1.2 2023-06-19 22:40:16 +06:00
d7eb0093d8 Update README.md 2023-06-10 18:16:35 +06:00
deba12ed5d update dokka and gradle wrapper version 2023-06-09 12:08:57 +06:00
f608cf4bef Merge pull request #25 from InsanusMokrassar/renovate/configure
Configure Renovate
2023-04-25 12:27:29 +06:00
renovate[bot]
4a656d2d90 Add renovate.json 2023-04-18 08:23:00 +00:00
c730f49fbd Merge pull request #24 from InsanusMokrassar/1.1.1
1.1.1
2023-04-13 11:09:15 +06:00
2a36f64b51 add actual defaultLogging in wasm 2023-04-13 10:58:07 +06:00
604ef1b347 add wasm support 2023-04-13 10:52:05 +06:00
dc50977c9a KSLog factory fix 2023-04-13 10:33:13 +06:00
7c0650e2df start 1.1.1 2023-04-13 10:31:50 +06:00
387ca9097c Merge pull request #23 from InsanusMokrassar/1.1.0
1.1.0
2023-04-12 23:21:54 +06:00
a71405aff5 small improvements in KSLog 2023-04-12 22:42:17 +06:00
a2b497d0f9 update dependencies 2023-04-12 22:35:34 +06:00
c5974fb51c start 1.1.0 2023-04-12 22:33:22 +06:00
3240b63f21 Enlarge Java Heap space 2023-03-12 19:38:22 +06:00
fffafc4da7 Update libs.versions.toml 2023-03-12 19:34:08 +06:00
b1d5ce2135 Merge pull request #22 from InsanusMokrassar/1.0.0
1.0.0
2023-01-04 20:26:35 +06:00
0b8db9be35 Update CHANGELOG.md 2023-01-04 08:59:46 +06:00
5030ecc255 Update libs.versions.toml 2023-01-03 08:27:35 +06:00
b5669d2187 start 1.0.0 2023-01-03 08:23:30 +06:00
ed7ad35605 update publishing workflows 2022-12-05 15:53:37 +06:00
6d5ddafefc update publishing scripts 2022-12-05 15:51:11 +06:00
ee31c61677 Merge pull request #21 from InsanusMokrassar/0.5.4
0.5.4
2022-12-05 15:32:45 +06:00
1be14aa28e Update CHANGELOG.md 2022-12-05 15:32:27 +06:00
97b432c0b0 Update CHANGELOG.md 2022-12-05 08:06:39 +06:00
74a0ad8fd1 Update libs.versions.toml 2022-12-05 07:53:25 +06:00
502dd4d607 Update libs.versions.toml 2022-12-05 07:51:29 +06:00
079fbaa7f4 Update libs.versions.toml 2022-11-28 16:40:04 +06:00
99dac12a27 Update gradle.properties 2022-11-28 16:38:43 +06:00
b0cc6c11ea add platforms support badges 2022-11-28 13:28:13 +06:00
58161132dc Merge pull request #20 from InsanusMokrassar/0.5.3
0.5.3
2022-11-03 13:27:17 +06:00
7e45e5d421 Update CHANGELOG.md 2022-11-03 13:27:02 +06:00
e7956f6d31 Update README.md 2022-11-03 13:22:23 +06:00
9993fd5fdd Update libs.versions.toml 2022-11-03 13:11:51 +06:00
9e8665cdc9 Update gradle.properties 2022-11-03 13:09:32 +06:00
63d3cabc9c Merge pull request #19 from InsanusMokrassar/0.5.2
0.5.2
2022-09-12 15:46:27 +06:00
44 changed files with 2350 additions and 117 deletions

View File

@@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Build
run: ./gradlew dokkaHtml
- name: Publish KDocs

View File

@@ -7,10 +7,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 11
- name: Fix android 32.0.0 dx
continue-on-error: true
run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
java-version: 17
- name: Rewrite version
run: |
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
@@ -19,6 +16,11 @@ jobs:
mv gradle.properties.tmp gradle.properties
- name: Build
run: ./gradlew build
- name: Publish to Gitea
continue-on-error: true
run: ./gradlew publishAllPublicationsToGiteaRepository
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Publish
continue-on-error: true
run: ./gradlew --no-parallel publishAllPublicationsToGithubPackagesRepository

1
.gitignore vendored
View File

@@ -12,6 +12,5 @@ out/
secret.gradle
local.*
local/
kotlin-js-store/
publishing.sh

View File

@@ -1,5 +1,80 @@
# Changelog
## 1.3.4
* `Kotlin`: `1.9.24`
* Native realization of `KSLoggerDefaultPlatformLoggerLambda` now is common for all native targets
## 1.3.3
* `Kotlin`: `1.9.23`
## 1.3.2
* `Kotlin`: `1.9.22`
## 1.3.1
* `Kotlin`: `1.9.21`
## 1.3.0
**THIS UPDATE CONTAINS CHANGES OF LOG LEVELS ACCORDANCES. LOOK AT THE LEVELS ACCORDANCE IN THE [DOCUMENTATION](https://docs.inmo.dev/kslog/logging.html#logging)
FOR MORE INFO**
* Add `trace` logging level
* Change overall table of log level accordance
* Now you may change default platform logger
## 1.2.4
**This update contains migration onto gradle 8+ (for both wrapper and android plugin). Use it with caution**
## 1.2.3
* `Kotlin`: `1.9.20`
## 1.2.2
**wasm32 target has been removed**
**mingwX86 target has been removed**
* `Kotlin`: `1.9.20-RC`
## 1.2.1
* `Kotlin`: `1.9.10`
* Latest supported android sdk now is `34`
## 1.2.0
* `Kotlin`: `1.9.0`
## 1.1.2
* `Kotlin`: `1.8.22`
## 1.1.1
* Rollback `KSLog` with `String` arg factory to use `DefaultKSLog`
## 1.1.0
* `Kotlin`: `1.8.20`
* Standard factory `KSLog` with `String` arg now use `TagLogger`
## 1.0.0
* `Kotlin`: `1.8.0`
## 0.5.4
* `Kotlin`: `1.7.22`
## 0.5.3
* `Kotlin`: `1.7.20`
## 0.5.2
* Add support of next platform:

View File

@@ -1,18 +1,33 @@
# How to use
# KSLog
It is simple and easy-to-use tool for logging on the most popular platforms in Kotlin Multiplatform:
![JVM](https://img.shields.io/badge/JVM-red?style=for-the-badge&logo=openjdk&logoColor=white)
![Android](https://img.shields.io/badge/Android-green?style=for-the-badge&logo=android&logoColor=white)
![Js](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge&logo=javascript&logoColor=F7DF1E)
![ARM x64](https://img.shields.io/badge/ARMx64-0091BD?style=for-the-badge&logo=arm&logoColor=F7DF1E)
![ARM x32](https://img.shields.io/badge/ARMx32-0091BD?style=for-the-badge&logo=arm&logoColor=F7DF1E)
![Linux x64](https://img.shields.io/badge/Linuxx64-FCC624?style=for-the-badge&logo=linux&logoColor=F7DF1E)
[![KDocs](https://img.shields.io/badge/KDocs-323330?style=for-the-badge&logo=Kotlin&logoColor=7F52FF)](https://insanusmokrassar.github.io/KSLog/)
[![Tutorials](https://img.shields.io/badge/Tutorials-0288D1?style=for-the-badge&logo=bookstack&logoColor=white)](https://bookstack.inmo.dev/books/kslog)
[![Tutorials](https://img.shields.io/badge/Tutorials-0288D1?style=for-the-badge&logo=mkdocs&logoColor=white)](https://docs.inmo.dev/kslog/index.html)
It is simple logging tool which is using built-in tools for logging:
By default, KSLog is using built-in tools for logging on each supported platform:
* `java.util.logging.Logger` for `JVM`
* `android.util.Log` for `Android`
* `Console` for `JS`
But you always may create your logger and customize as you wish:
```kotlin
KSLog.default = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
// do your logging
}
```
**This library also supports native targets in experimental mode. By default all native targets will use simple printing in the console**
## How to use
### Fast-travel
@@ -39,9 +54,11 @@ KSLog.l(LogLevel.INFO, "Some optional tag", IllegalArgumentException("So, that i
There are several important "terms" in context of this library:
* Default logger (available via `KSLog.default`)
* Default logger (available via `KSLog.default` or simply `KSLog`)
* Local logger (can be created via `KSLog` functions and passed anywhere as `KSLog`)
* Logging shortcuts like `KSLog.i`/`KSLog.info`
* Built-in extension `Any.logger` which allow you to create logger binded to the default with the tag based on the class of receiver
* __Be careful with the receivers: if you will use some extension like `apply`, the receiver will be different with your class inside of that `apply`__
Every logging extension (like `KSLog.i`) have its analog with lazy inited message text and the same one with suffix `S` (like `KSLog.iS`) for the suspendable message calculation.

View File

@@ -19,6 +19,7 @@ buildscript {
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.dokka)
alias(libs.plugins.versions)
}
apply plugin: "com.android.library"
@@ -44,15 +45,23 @@ kotlin {
browser()
nodejs()
}
android {
androidTarget {
publishAllLibraryVariants()
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
linuxArm64()
linuxArm32Hfp()
linuxX64()
wasm32()
wasm {
browser()
nodejs()
d8()
}
mingwX64()
mingwX86()
sourceSets {
commonMain {
@@ -60,6 +69,13 @@ kotlin {
implementation libs.kotlin
}
}
commonTest {
dependencies {
implementation libs.kotlin.test.common
implementation libs.kotlin.test.annotations.common
implementation libs.kotlin.test.junit
}
}
}
}

View File

@@ -26,8 +26,9 @@ android {
}
}
compileSdkVersion libs.versions.android.compileSdk.get().toInteger()
buildToolsVersion libs.versions.android.buildTools.get()
compileSdk libs.versions.android.compileSdk.get().toInteger()
buildToolsVersion = libs.versions.android.buildTools.get()
namespace "${group}.${project.name}"
defaultConfig {
minSdkVersion libs.versions.android.minSdk.get().toInteger()
@@ -51,12 +52,8 @@ android {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
sourceSets {

View File

@@ -18,13 +18,13 @@ if (new File(projectDir, "secret.gradle").exists()) {
githubRelease {
token "${project.property('GITHUB_RELEASE_TOKEN')}"
owner "InsanusMokrassar"
repo "KSLog"
owner = "InsanusMokrassar"
repo = "KSLog"
tagName "v${project.version}"
releaseName "${project.version}"
targetCommitish "${project.version}"
tagName = "v${project.version}"
releaseName = "${project.version}"
targetCommitish = "${project.version}"
body getCurrentVersionChangelog()
body = getCurrentVersionChangelog()
}
}

View File

@@ -5,10 +5,10 @@ kotlin.incremental=true
kotlin.incremental.js=true
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx196m
org.gradle.jvmargs=-Xmx512m
# Project data
group=dev.inmo
version=0.5.2
android_code_version=15
version=1.3.4
android_code_version=31

View File

@@ -1,18 +1,22 @@
[versions]
kotlin = "1.7.10"
kotlin-gradle-plugin = "7.2.2"
kotlin = "1.9.24"
kotlin-gradle-plugin = "8.3.2"
dexcount = "3.1.0"
versions = "0.51.0"
dokka = "1.9.20"
dexcount = "4.0.0"
junit_version = "4.12"
test_ext_junit_version = "1.1.3"
espresso_core = "3.4.0"
test_ext_junit_version = "1.1.5"
espresso_core = "3.5.1"
android-minSdk = "21"
android-compileSdk = "32"
android-buildTools = "32.0.0"
android-compileSdk = "34"
android-buildTools = "34.0.0"
github-release = "2.4.1"
github-release = "2.5.2"
[libraries]
@@ -29,10 +33,12 @@ android-test-espresso-core = { module = "androidx.test.espresso:espresso-core",
android-tools-build = { module = "com.android.tools.build:gradle", version.ref = "kotlin-gradle-plugin" }
android-dexcount = { module = "com.getkeepsafe.dexcount:dexcount-gradle-plugin", version.ref = "dexcount" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "kotlin" }
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
github-release = { module = "com.github.breadmoirai:github-release", version.ref = "github-release" }
[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "kotlin" }
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

1921
kotlin-js-store/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
apply plugin: 'maven-publish'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
}
publishing {
@@ -49,20 +49,36 @@ publishing {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/KSLog")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('INMONEXUS_USER') || System.getenv('INMONEXUS_USER') != null) && (project.hasProperty('INMONEXUS_PASSWORD') || System.getenv('INMONEXUS_PASSWORD') != null)) {
maven {
name = "InmoNexus"
url = uri("https://nexus.inmo.dev/repository/maven-releases/")
credentials {
username = project.hasProperty('INMONEXUS_USER') ? project.property('INMONEXUS_USER') : System.getenv('INMONEXUS_USER')
password = project.hasProperty('INMONEXUS_PASSWORD') ? project.property('INMONEXUS_PASSWORD') : System.getenv('INMONEXUS_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
@@ -83,4 +99,27 @@ if (project.hasProperty("signing.gnupg.keyName")) {
dependsOn(it)
}
}
// Workaround to make android sign operations depend on signing tasks
project.getTasks().withType(AbstractPublishToMaven.class).configureEach {
def signingTasks = project.getTasks().withType(Sign.class)
mustRunAfter(signingTasks)
}
// Workaround to make test tasks use sign
project.getTasks().withType(Sign.class).configureEach { signTask ->
def withoutSign = (signTask.name.startsWith("sign") ? signTask.name.minus("sign") : signTask.name)
def pubName = withoutSign.endsWith("Publication") ? withoutSign.substring(0, withoutSign.length() - "Publication".length()) : withoutSign
// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets
// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
def debugTestTask = tasks.findByName("linkDebugTest$pubName")
if (debugTestTask != null) {
signTask.mustRunAfter(debugTestTask)
}
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
def testTask = tasks.findByName("compileTestKotlin$pubName")
if (testTask != null) {
signTask.mustRunAfter(testTask)
}
}
}

View File

@@ -1 +1 @@
{"licenses":[{"id":"MIT","title":"MIT License","url":"https://opensource.org/licenses/MIT"}],"mavenConfig":{"name":"${project.name}","description":"Simple logging library for kotlin","url":"https://github.com/InsanusMokrassar/KSLog","vcsUrl":"https://github.com/InsanusMokrassar/KSLog.git","developers":[{"id":"Akkihi","name":"Akkihi","eMail":"akkihiguy@gmail.com"},{"id":"InsanusMokrassar","name":"InsanusMokrassar","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/KSLog"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
{"licenses":[{"id":"MIT","title":"MIT License","url":"https://opensource.org/licenses/MIT"}],"mavenConfig":{"name":"${project.name}","description":"Simple logging library for kotlin","url":"https://github.com/InsanusMokrassar/KSLog","vcsUrl":"https://github.com/InsanusMokrassar/KSLog.git","developers":[{"id":"Akkihi","name":"Akkihi","eMail":"akkihiguy@gmail.com"},{"id":"InsanusMokrassar","name":"InsanusMokrassar","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/KSLog"},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}

6
renovate.json Normal file
View File

@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}

View File

@@ -1,3 +1 @@
rootProject.name = 'kslog'
enableFeaturePreview("VERSION_CATALOGS")

View File

@@ -2,10 +2,10 @@ package dev.inmo.kslog.common
import android.util.Log
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
val messageString = m.toString()
when(l) {
LogLevel.TRACE -> Log.d(t, messageString, e)
LogLevel.DEBUG -> Log.d(t, messageString, e)
LogLevel.VERBOSE -> Log.v(t, messageString, e)
LogLevel.INFO -> Log.i(t, messageString, e)

View File

@@ -1,8 +1,20 @@
package dev.inmo.kslog.common
/**
* Creating base tag using class simple name of receiver
*
* @throws IllegalStateException If there is no opportunity to take simple name of receiver class
*/
val Any.logTag
get() = this::class.simpleName ?: error("Unable to retrieve log tag")
/**
* Creating [TagLogger] with [logTag] as base tag
*/
val Any.logger: KSLog
get() = TagLogger(logTag)
/**
* Creating [TagLogger] using [logger] extension property with [tagBase] as `this`
*/
fun taggedLogger(tagBase: Any): KSLog = tagBase.logger

View File

@@ -1,13 +1,22 @@
package dev.inmo.kslog.common
import kotlin.jvm.JvmInline
typealias SimpleKSLogCallback = (level: LogLevel, tag: String?, message: Any, throwable: Throwable?) -> Unit
class CallbackKSLog(
/**
* Creates simple [KSLog] which will pass all incoming [performLog] calls to [performLogCallback]
*/
@JvmInline
value class CallbackKSLog(
private val performLogCallback: SimpleKSLogCallback
) : KSLog {
override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) = performLogCallback(level, tag, message, throwable)
}
/**
* Creating [CallbackKSLog] using [performLogCallback] as an argument for constructor
*/
fun KSLog(
performLogCallback: SimpleKSLogCallback
) = CallbackKSLog(performLogCallback)

View File

@@ -2,23 +2,32 @@ package dev.inmo.kslog.common
import dev.inmo.kslog.common.filter.filtered
/**
* Logger based on [KSLoggerDefaultPlatformLoggerLambda] or [logging] parameter
*
* @param defaultTag will be used in case when `tag` parameter in [performLog] omitted
* @param messageFormatter special formatter which creating [String] inside of [performLog] for each call. Defaults to
* [defaultMessageFormatter]
* @param logging target lambda which will be called with a result of [messageFormatter] logs formatting as a message
* and tag as tag if not `null` and [defaultTag] otherwise
*/
class DefaultKSLog(
private val defaultTag: String,
private val messageFormatter: MessageFormatter = defaultMessageFormatter,
private val logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = defaultLogging
private val logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = KSLoggerDefaultPlatformLoggerLambda
) : KSLog {
override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) {
val tag = tag ?: defaultTag
val resultTag = tag ?: defaultTag
val text = messageFormatter(level, tag, message, throwable)
logging(level, tag, text, throwable)
val text = messageFormatter(level, resultTag, message, throwable)
logging(level, resultTag, text, throwable)
}
override fun performLog(level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> Any) {
val tag = tag ?: defaultTag
val resultTag = tag ?: defaultTag
val text = messageFormatter(level, tag, messageBuilder(), throwable)
logging(level, tag, text, throwable)
val text = messageFormatter(level, resultTag, messageBuilder(), throwable)
logging(level, resultTag, text, throwable)
}
override suspend fun performLogS(
@@ -27,10 +36,10 @@ class DefaultKSLog(
throwable: Throwable?,
messageBuilder: suspend () -> Any
) {
val tag = tag ?: defaultTag
val resultTag = tag ?: defaultTag
val text = messageFormatter(level, tag, messageBuilder(), throwable)
logging(level, tag, text, throwable)
val text = messageFormatter(level, resultTag, messageBuilder(), throwable)
logging(level, resultTag, text, throwable)
}
}
@@ -39,7 +48,7 @@ fun DefaultKSLog(
defaultTag: String,
filter: MessageFilter = { _, _, _ -> true },
messageFormatter: MessageFormatter = defaultMessageFormatter,
logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = defaultLogging
logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = KSLoggerDefaultPlatformLoggerLambda
) = DefaultKSLog(
defaultTag, messageFormatter, logging
).filtered(filter)

View File

@@ -15,6 +15,19 @@ inline fun KSLog.log(level: LogLevel, tag: String, message: Any, e: Throwable?)
inline fun KSLog.log(level: LogLevel, tag: String, message: Any) = performLog(level, tag, message, null)
inline fun KSLog.trace(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, null, e, messageBuilder)
inline fun KSLog.trace(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, tag, e, messageBuilder)
inline fun KSLog.trace(tag: String, noinline messageBuilder: () -> Any) = trace(tag, null, messageBuilder)
suspend inline fun KSLog.traceS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, null, e, messageBuilder)
suspend inline fun KSLog.traceS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, tag, e, messageBuilder)
suspend inline fun KSLog.traceS(tag: String, noinline messageBuilder: suspend () -> Any) = traceS(tag, null, messageBuilder)
inline fun KSLog.trace(message: Any, e: Throwable?) = log(LogLevel.TRACE, message, e)
inline fun KSLog.trace(message: String, e: Throwable) = trace(message as Any, e)
inline fun KSLog.trace(message: Any) = trace(message, null)
inline fun KSLog.trace(tag: String, message: Any, e: Throwable?) = log(LogLevel.TRACE, tag, message, e)
inline fun KSLog.trace(tag: String, message: Any) = trace(tag, message, null)
inline fun KSLog.debug(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, null, e, messageBuilder)
inline fun KSLog.debug(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, tag, e, messageBuilder)
inline fun KSLog.debug(tag: String, noinline messageBuilder: () -> Any) = debug(tag, null, messageBuilder)
@@ -108,6 +121,19 @@ inline fun KSLog.l(level: LogLevel, tag: String, message: Any, e: Throwable?) =
inline fun KSLog.l(level: LogLevel, tag: String, message: Any) = log(level, tag, message, null)
inline fun KSLog.t(e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(e, messageBuilder)
inline fun KSLog.t(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(tag, e, messageBuilder)
inline fun KSLog.t(tag: String, noinline messageBuilder: () -> Any) = t(tag, null, messageBuilder)
suspend inline fun KSLog.tS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(e, messageBuilder)
suspend inline fun KSLog.tS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(tag, e, messageBuilder)
suspend inline fun KSLog.tS(tag: String, noinline messageBuilder: suspend () -> Any) = tS(tag, null, messageBuilder)
inline fun KSLog.t(message: Any, e: Throwable?) = trace(message, e)
inline fun KSLog.t(message: String, e: Throwable) = t(message as Any, e)
inline fun KSLog.t(message: Any) = t(message, null)
inline fun KSLog.t(tag: String, message: Any, e: Throwable?) = trace(tag, message, e)
inline fun KSLog.t(tag: String, message: Any) = t(tag, message, null)
inline fun KSLog.d(e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(e, messageBuilder)
inline fun KSLog.d(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(tag, e, messageBuilder)
inline fun KSLog.d(tag: String, noinline messageBuilder: () -> Any) = d(tag, null, messageBuilder)

View File

@@ -5,6 +5,7 @@ import dev.inmo.kslog.common.utils.plus
enum class LogLevel {
TRACE,
DEBUG,
VERBOSE,
INFO,
@@ -13,15 +14,38 @@ enum class LogLevel {
ASSERT,
}
/**
* Base interface for any logger
*
* @see default
*
*/
interface KSLog {
/**
* The only one function required to realization in any inheritor. All other [performLog] functions
* will call this one by default
*/
fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?)
/**
* Calls default [performLog] with `tag` == `null`
*/
fun performLog(level: LogLevel, message: Any, throwable: Throwable?) = performLog(level, null, message, throwable)
/**
* Calls default [performLog] with `message` built using [messageBuilder]. This method supposed to be overriden in
* case when logger supports lazy-loaded messages (like [dev.inmo.kslog.common.filter.FilterKSLog])
*/
fun performLog(
level: LogLevel,
tag: String?,
throwable: Throwable?,
messageBuilder: () -> Any
) = performLog(level, tag, messageBuilder(), throwable)
/**
* Suspendable variant of [performLog] with [messageBuilder]. Uses default [performLog] with `message` built using
* [messageBuilder] by default
*/
suspend fun performLogS(
level: LogLevel,
tag: String?,
@@ -32,6 +56,10 @@ interface KSLog {
companion object : KSLog {
private var defaultLogger: KSLog? = null
/**
* Default logger used in case you are trying to use [KSLog] as a receiver for extensions like [info]
*/
var default: KSLog
get() {
return defaultLogger ?: KSLog("app").also {
@@ -61,14 +89,23 @@ interface KSLog {
operator fun KSLog.invoke(performLogCallback: (level: LogLevel, tag: String?, message: Any, throwable: Throwable?) -> Unit) = CallbackKSLog(performLogCallback)
internal expect val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
internal val printlnLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
println(defaultMessageFormatter(l, t, m, e))
}
/**
* Simple builder for [DefaultKSLog] logger based on [defaultTag]
*/
fun KSLog(
defaultTag: String,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog = DefaultKSLog(defaultTag)
/**
* Simple builder for [DefaultKSLog] logger based on [defaultTag] and [messageFormatter]
*/
fun KSLog(
defaultTag: String,
messageFormatter: MessageFormatter
): KSLog = DefaultKSLog(
defaultTag,
messageFormatter
@@ -79,23 +116,30 @@ fun KSLog(
defaultTag: String,
filter: MessageFilter,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog = DefaultKSLog(
): KSLog = KSLog (
defaultTag,
filter,
messageFormatter
)
).filtered(filter)
/**
* Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter
* incoming levels: only levels passed in [levels] param will be logged
*/
fun KSLog(
defaultTag: String,
levels: Iterable<LogLevel>,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog {
val levels = levels.toSet()
val levelsSet = levels.toSet()
return KSLog (defaultTag, messageFormatter).filtered { l, _, _ ->
l in levels
l in levelsSet
}
}
/**
* Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter
* incoming levels: only levels passed in [firstLevel], [secondLevel] and [otherLevels] param will be logged
*/
fun KSLog(
defaultTag: String,
firstLevel: LogLevel,
@@ -104,6 +148,10 @@ fun KSLog(
messageFormatter: MessageFormatter = defaultMessageFormatter,
): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter)
/**
* Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter
* incoming levels: only levels above [minLoggingLevel] will be logged
*/
fun KSLog(
defaultTag: String,
minLoggingLevel: LogLevel,
@@ -115,5 +163,13 @@ fun KSLog(
minLoggingLevel.ordinal <= l.ordinal
}
/**
* Setting [KSLog.default] logger to [newDefault]
*/
fun setDefaultKSLog(newDefault: KSLog) { KSLog.default = newDefault }
fun addDefaultKSLog(newDefault: KSLog) { KSLog.default = KSLog.default + newDefault }
/**
* Setting [KSLog.default] logger to new [CallbackKSLog] using [plus] operation
*/
fun addDefaultKSLog(newDefault: KSLog) {
KSLog.default += newDefault
}

View File

@@ -1,7 +1,6 @@
package dev.inmo.kslog.common
typealias MessageFormatter = (l: LogLevel, t: String?, m: Any, Throwable?) -> String
@Suppress("NOTHING_TO_INLINE")
inline fun MessageFormatter(noinline formatter: MessageFormatter) = formatter
typealias MessageFilter = (l: LogLevel, t: String?, Throwable?) -> Boolean
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] ${t ?.let { "$it " } ?: ""}- $m" }

View File

@@ -0,0 +1,7 @@
package dev.inmo.kslog.common
/**
* Default logger for current platform. You may change it, but you should remember that it is global logger
* used in [KSLog.default] by default
*/
expect var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit

View File

@@ -2,6 +2,9 @@ package dev.inmo.kslog.common
import kotlin.jvm.JvmInline
/**
* Logger which will use [tag] as default one in cases when [performLog] have `null` tag
*/
@JvmInline
value class TagLogger(val tag: String) : KSLog {
override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) {

View File

@@ -2,6 +2,10 @@ package dev.inmo.kslog.common.filter
import dev.inmo.kslog.common.*
/**
* In its [performLog]/[performLogS] methods do logging only in cases when [messageFilter] returns true for incoming
* parameters
*/
class FilterKSLog(
private val fallbackLogger: KSLog,
private val messageFilter: MessageFilter

View File

@@ -3,6 +3,9 @@ package dev.inmo.kslog.common.filter
import dev.inmo.kslog.common.KSLog
import dev.inmo.kslog.common.MessageFilter
/**
* Creates [FilterKSLog] with applying of [filter] to it
*/
fun KSLog.filtered(
filter: MessageFilter
) = FilterKSLog(this, filter)

View File

@@ -3,6 +3,11 @@ package dev.inmo.kslog.common.typed
import dev.inmo.kslog.common.*
import kotlin.reflect.KClass
/**
* Uses [typedLoggers] [Map] to determine, where incoming __message__s should be sent. If there is no [KClass] key for
* incoming message in [typedLoggers], logger will use logger by `null` key if exists. If there is no default logger
* (by `null` key), logging will be skipped
*/
class TypedKSLog(
private val typedLoggers: Map<KClass<*>?, KSLog>
) : KSLog {

View File

@@ -3,6 +3,9 @@ package dev.inmo.kslog.common.typed
import dev.inmo.kslog.common.*
import kotlin.reflect.KClass
/**
* Special builder for [TypedKSLog]
*/
class TypedKSLogBuilder(
private val preset: Map<KClass<*>?, KSLog> = emptyMap()
) {
@@ -22,6 +25,9 @@ class TypedKSLogBuilder(
fun build() = TypedKSLog(loggers.toMap())
}
/**
* DSL for [TypedKSLogBuilder]
*/
inline fun buildTypedLogger(
preset: Map<KClass<*>?, KSLog> = emptyMap(),
block: TypedKSLogBuilder.() -> Unit

View File

@@ -3,6 +3,10 @@ package dev.inmo.kslog.common.utils
import dev.inmo.kslog.common.CallbackKSLog
import dev.inmo.kslog.common.KSLog
/**
* Will send [KSLog.performLog] of both [this] and [other] [KSLog] instances. In case when [this] will throw exception
* result logger will rethrow it. After it, if [other] will throw exception - will also rethrow it
*/
infix operator fun KSLog.plus(other: KSLog) = CallbackKSLog { l, t, m, e ->
val resultOfFirst = runCatching {
this@plus.performLog(l, t, m, e)

View File

@@ -1,15 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
val args = e ?.let {
arrayOf(m, e)
} ?: arrayOf(m)
when (l) {
LogLevel.DEBUG -> console.log(*args)
LogLevel.VERBOSE,
LogLevel.INFO -> console.info(*args)
LogLevel.WARNING -> console.warn(*args)
LogLevel.ERROR,
LogLevel.ASSERT -> console.error(*args)
}
}

View File

@@ -0,0 +1,24 @@
package dev.inmo.kslog.common
import kotlin.js.Console
external interface ExtendedConsole : Console {
fun trace()
fun debug(vararg o: Any?)
fun assert(assertion: Boolean, vararg o: Any?)
}
/**
* [https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static](https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static)
*/
fun Console.debug(vararg args: Any?) = unsafeCast<ExtendedConsole>().debug(*args)
/**
* [https://developer.mozilla.org/en-US/docs/Web/APtraceI/console/assert_static](https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static)
*/
fun Console.assert(assertion: Boolean, vararg args: Any?) = unsafeCast<ExtendedConsole>().assert(assertion, *args)
/**
* [https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static](https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static)
*/
fun Console.trace() = unsafeCast<ExtendedConsole>().trace()

View File

@@ -0,0 +1,19 @@
package dev.inmo.kslog.common
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, _, m, e ->
val args = e ?.let {
arrayOf(m, e)
} ?: arrayOf(m)
when (l) {
LogLevel.TRACE -> {
console.trace()
console.debug(*args)
}
LogLevel.DEBUG -> console.debug(*args)
LogLevel.VERBOSE,
LogLevel.INFO -> console.info(*args)
LogLevel.WARNING -> console.warn(*args)
LogLevel.ERROR -> console.error(*args)
LogLevel.ASSERT -> console.error(*args)
}
}

View File

@@ -4,14 +4,15 @@ import dev.inmo.kslog.common.filter.filtered
import java.util.logging.Level
import java.util.logging.Logger
private val defaultKSLogLogger by lazy {
internal val defaultKSLogLogger by lazy {
Logger.getLogger("KSLog")
}
private fun Logger.doLog(
internal fun Logger.doLog(
l: LogLevel, t: String, m: String, e: Throwable?
) = log(
when(l) {
LogLevel.DEBUG -> Level.FINEST
LogLevel.TRACE -> Level.FINEST
LogLevel.DEBUG -> Level.FINER
LogLevel.VERBOSE -> Level.FINE
LogLevel.INFO -> Level.INFO
LogLevel.WARNING -> Level.WARNING
@@ -21,9 +22,6 @@ private fun Logger.doLog(
m,
e
)
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
defaultKSLogLogger.doLog(l, t, m.toString(), e)
}
@Deprecated("Filtering should be replaced with FilterKSLog")
fun KSLog(
@@ -52,8 +50,8 @@ fun KSLog(
levels: Iterable<LogLevel>,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog {
val levels = levels.toSet()
return KSLog (defaultTag, logger, messageFormatter).filtered { l, _, _ -> l in levels }
val levelsSet = levels.toSet()
return KSLog (defaultTag, logger, messageFormatter).filtered { l, _, _ -> l in levelsSet }
}
fun KSLog(

View File

@@ -0,0 +1,5 @@
package dev.inmo.kslog.common
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
defaultKSLogLogger.doLog(l, t, m.toString(), e)
}

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -1 +0,0 @@
<manifest package="dev.inmo.kslog"/>

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -0,0 +1,4 @@
package dev.inmo.kslog.common
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit =
printlnLogging

View File

@@ -1,4 +0,0 @@
package dev.inmo.kslog.common
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
get() = printlnLogging

View File

@@ -0,0 +1,4 @@
package dev.inmo.kslog.common
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit =
printlnLogging