Compare commits

..

111 Commits

Author SHA1 Message Date
7f92a3e614 generate kdocs 2025-11-12 13:45:57 +06:00
3c4e59ddc2 update dependencies 2025-11-12 13:25:11 +06:00
461bc92966 start 1.5.2 2025-11-12 13:06:43 +06:00
8c0968ba86 Merge pull request #108 from InsanusMokrassar/1.5.1
1.5.1
2025-09-30 23:19:40 +06:00
526de46a98 update dependencies 2025-09-30 23:19:00 +06:00
0af8c78e37 start 1.5.1 2025-09-30 23:12:06 +06:00
6840598e04 fix publishing? 2025-06-30 20:28:52 +06:00
7a2d070ee3 fix of publishing scripts 2025-06-30 18:02:47 +06:00
92651d3ba6 Merge pull request #101 from InsanusMokrassar/1.5.0
1.5.0
2025-06-30 14:43:28 +06:00
b8c72f1131 update dependencies 2025-06-29 18:46:36 +06:00
9b92fa29f4 start 1.5.0 2025-06-29 18:36:26 +06:00
42ced6edd2 Update github_release.gradle 2025-05-16 12:38:00 +06:00
dd3e4c4c2a Update github_release.gradle 2025-05-16 12:20:39 +06:00
f528909915 Merge pull request #98 from InsanusMokrassar/1.4.2
1.4.2
2025-05-16 09:05:00 +06:00
b3919c8439 update dependencies 2025-05-16 08:58:52 +06:00
d1dd159e36 update publication script 2025-05-16 08:55:04 +06:00
3db55982e9 start 1.4.2 2025-05-16 08:48:08 +06:00
8e477b1056 Merge pull request #95 from InsanusMokrassar/1.4.1
1.4.1
2025-01-29 12:36:18 +06:00
480d2c8132 update dependencies 2025-01-29 12:06:52 +06:00
a2a73dfe83 start 1.4.1 2025-01-29 12:06:20 +06:00
4528918347 Merge pull request #92 from InsanusMokrassar/renovate/major-dokka
Update dokka to v2 (major)
2025-01-10 08:21:30 +06:00
renovate[bot]
9ef93724ad Update dokka to v2 2024-12-21 02:49:05 +00:00
dccbd13788 Merge pull request #90 from InsanusMokrassar/1.4.0
1.4.0
2024-12-09 10:10:09 +06:00
8bb34d6842 update dependencies 2024-12-09 10:04:09 +06:00
cff3f71de7 start 1.4.0 2024-12-09 10:03:14 +06:00
aab0ac064f Merge pull request #87 from InsanusMokrassar/1.3.6
1.3.6
2024-08-27 19:13:32 +06:00
d2909ed5f0 update dependencies 2024-08-27 19:12:58 +06:00
81eba88ce9 start 1.3.6 2024-08-27 19:01:11 +06:00
a73f0d132c remove kotlin-js-store 2024-08-27 19:00:22 +06:00
bd87184f81 Merge pull request #84 from InsanusMokrassar/1.3.5
1.3.5
2024-08-09 23:07:10 +06:00
7228e81344 update android sdk version 2024-08-09 22:53:36 +06:00
ac828b1af7 update test dependencies and wrapper versions 2024-08-09 22:43:06 +06:00
a8c85b9614 fix of build 2024-08-09 22:34:05 +06:00
98fbf43d4d update kotlin 2024-08-09 22:28:55 +06:00
ef8a3e1500 start 1.3.5 2024-08-09 22:28:08 +06:00
3edbb78d56 Merge pull request #77 from InsanusMokrassar/1.3.4
1.3.4
2024-05-12 16:49:34 +06:00
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
44 changed files with 986 additions and 180 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

4
.gitignore vendored
View File

@@ -1,4 +1,6 @@
.idea
.kotlin
kotlin-js-store/
out/*
*.iml
target
@@ -12,6 +14,6 @@ out/
secret.gradle
local.*
local/
kotlin-js-store/
**/*.local.*
publishing.sh

View File

@@ -1,5 +1,106 @@
# Changelog
## 1.5.2
* `Kotlin`: `2.2.21`
## 1.5.1
* `Kotlin`: `2.2.20`
## 1.5.0
* `Kotlin`: `2.2.0`
## 1.4.2
* `Kotlin`: `2.1.21`
* Android SDK Level: `36`
## 1.4.1
* `Kotlin`: `2.1.10`
## 1.4.0
* `Kotlin`: `2.1.0`
## 1.3.6
* `Kotlin`: `2.0.20`
## 1.3.5
* `Kotlin`: `2.0.10`
* Android SDK Level: `35`
## 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`

View File

@@ -10,7 +10,7 @@ It is simple and easy-to-use tool for logging on the most popular platforms in K
![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)
By default, KSLog is using built-in tools for logging on each supported platform:

View File

@@ -19,9 +19,30 @@ buildscript {
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.dokka)
alias(libs.plugins.versions)
alias(libs.plugins.nmcp.aggregation)
}
apply plugin: "com.android.library"
apply from: "defaultAndroidSettings.gradle"
apply from: "github_release.gradle"
apply from: "publish.gradle"
apply from: "dokka.gradle"
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
nmcpAggregation {
centralPortal {
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')
validationTimeout = Duration.ofHours(4)
publishingType = System.getenv('PUBLISHING_TYPE') != "" ? System.getenv('PUBLISHING_TYPE') : "USER_MANAGED"
}
publishAllProjectsProbablyBreakingProjectIsolation()
}
}
project.version = "$version"
project.group = "$group"
@@ -44,15 +65,26 @@ kotlin {
browser()
nodejs()
}
android {
publishAllLibraryVariants()
androidTarget {
publishLibraryVariants(
"release",
"debug",
)
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
linuxArm64()
linuxArm32Hfp()
linuxX64()
wasm32()
wasm {
browser()
nodejs()
d8()
}
mingwX64()
mingwX86()
sourceSets {
commonMain {
@@ -60,6 +92,17 @@ kotlin {
implementation libs.kotlin
}
}
commonTest {
dependencies {
implementation libs.kotlin.test.common
implementation libs.kotlin.test.annotations.common
}
}
jvmTest {
dependencies {
implementation libs.kotlin.test.junit
}
}
}
}
@@ -67,9 +110,3 @@ java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
apply from: "defaultAndroidSettings.gradle"
apply from: "github_release.gradle"
apply from: "publish.gradle"
apply from: "dokka.gradle"

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

@@ -11,20 +11,28 @@ private String getCurrentVersionChangelog() {
return changelogDataOS.toString().trim()
}
if (new File(projectDir, "secret.gradle").exists()) {
apply from: './secret.gradle'
def githubTokenVariableName = "GITHUB_RELEASE_TOKEN"
def githubTokenVariableFromEnv = System.getenv(githubTokenVariableName)
def secretFile = new File(projectDir, "secret.gradle")
if (secretFile.exists() || project.hasProperty(githubTokenVariableName) || (githubTokenVariableFromEnv != "" && githubTokenVariableFromEnv != null)) {
if (secretFile.exists()) {
apply from: './secret.gradle'
}
apply plugin: "com.github.breadmoirai.github-release"
def githubReleaseToken = project.hasProperty(githubTokenVariableName) ? project.property(githubTokenVariableName).toString() : githubTokenVariableFromEnv
githubRelease {
token "${project.property('GITHUB_RELEASE_TOKEN')}"
token githubReleaseToken
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.4
android_code_version=17
version=1.5.2
android_code_version=39

View File

@@ -1,20 +1,23 @@
[versions]
kotlin = "1.7.22"
kotlin-gradle-plugin = "7.2.2"
kotlin = "2.2.21"
kotlin-gradle-plugin = "8.12.+"
dokka = "1.7.20"
nmcp = "1.2.0"
versions = "0.53.0"
dexcount = "3.1.0"
dokka = "2.1.0"
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.3.0"
espresso_core = "3.7.0"
android-minSdk = "21"
android-compileSdk = "33"
android-buildTools = "33.0.0"
android-compileSdk = "36"
android-buildTools = "36.0.0"
github-release = "2.4.1"
github-release = "2.5.2"
[libraries]
@@ -38,3 +41,7 @@ github-release = { module = "com.github.breadmoirai:github-release", version.ref
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }
nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" }

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.14.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -1,7 +1,8 @@
apply plugin: 'maven-publish'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
}
publishing {
@@ -19,50 +20,47 @@ publishing {
}
developers {
developer {
id = "Akkihi"
name = "Akkihi"
email = "akkihiguy@gmail.com"
}
developer {
id = "Akkihi"
name = "Akkihi"
email = "akkihiguy@gmail.com"
}
developer {
id = "InsanusMokrassar"
name = "InsanusMokrassar"
email = "ovsyannikov.alexey95@gmail.com"
}
developer {
id = "InsanusMokrassar"
name = "InsanusMokrassar"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
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')
}
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
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')
}
}
}
repositories {
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://ossrh-staging-api.central.sonatype.com/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')
}
}
}
@@ -71,16 +69,39 @@ publishing {
if (project.hasProperty("signing.gnupg.keyName")) {
apply plugin: 'signing'
signing {
useGpgCmd()
sign publishing.publications
}
task signAll {
tasks.withType(Sign).forEach {
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":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/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

@@ -0,0 +1,31 @@
package dev.inmo.kslog.common
import android.util.Log
/**
* Android platform implementation of the default logger
*
* Uses Android's `[android.util.Log]` as the logging backend, mapping KSLog levels
* to Android log levels:
* - [LogLevel.TRACE] → [Log.d] (debug)
* - [LogLevel.DEBUG] → [Log.d] (debug)
* - [LogLevel.VERBOSE] → [Log.v] (verbose)
* - [LogLevel.INFO] → [Log.i] (info)
* - [LogLevel.WARNING] → [Log.w] (warning)
* - [LogLevel.ERROR] → [Log.e] (error)
* - [LogLevel.ASSERT] → [Log.wtf] (what a terrible failure)
*
* Logs can be viewed using `adb logcat` or Android Studio's Logcat window.
*/
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)
LogLevel.WARNING -> Log.w(t, messageString, e)
LogLevel.ERROR -> Log.e(t, messageString, e)
LogLevel.ASSERT -> Log.wtf(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

@@ -2,6 +2,18 @@
package dev.inmo.kslog.common
/**
* Extension functions for convenient logging with [KSLog]
*
* This file provides:
* - Generic log functions for all log levels
* - Specific functions for each log level (trace, debug, verbose, info, warning, error, assert)
* - Short aliases (t, d, v, i, w, e, wtf) for quick logging
* - Suspendable variants (with 'S' suffix) for async contexts
* - Support for lazy message evaluation via lambda builders
* - Both tagged and untagged variants
*/
inline fun KSLog.log(level: LogLevel, tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = performLog(level, tag, e, messageBuilder)
inline fun KSLog.log(level: LogLevel, tag: String, noinline messageBuilder: () -> Any) = performLog(level, tag, null, messageBuilder)
suspend inline fun KSLog.logS(level: LogLevel, tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = performLogS(level, tag, e, messageBuilder)
@@ -15,6 +27,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 +133,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

@@ -4,24 +4,105 @@ import dev.inmo.kslog.common.filter.filtered
import dev.inmo.kslog.common.utils.plus
/**
* Enumeration of all available log levels ordered from least to most severe
*
* Used to categorize and filter log messages by importance
*/
enum class LogLevel {
/** Trace level - most detailed logging, typically for tracing code execution */
TRACE,
/** Debug level - detailed information useful for debugging */
DEBUG,
/** Verbose level - detailed informational messages */
VERBOSE,
/** Info level - general informational messages about application state */
INFO,
/** Warning level - potentially harmful situations */
WARNING,
/** Error level - error events that might still allow the application to continue */
ERROR,
/** Assert level - severe errors that should never happen */
ASSERT,
}
/**
* Base interface for any logger in KSLog framework
*
* This is the core logging interface that all logger implementations must implement.
* It provides multiple overloads for logging messages with various combinations of parameters.
*
* The interface supports:
* - Synchronous and suspendable logging
* - Lazy message evaluation via lambda builders
* - Optional tags for categorizing logs
* - Exception/throwable logging
* - All standard log levels (TRACE, DEBUG, VERBOSE, INFO, WARNING, ERROR, ASSERT)
*
* @see default Default logger instance
* @see DefaultKSLog Default implementation
* @see FilterKSLog Logger with filtering capabilities
* @see TypedKSLog Logger with type-based routing
*/
interface KSLog {
/**
* The core logging method that must be implemented by all logger implementations
*
* All other [performLog] overloads will eventually call this method by default.
*
* @param level The severity level of the log message
* @param tag Optional tag to categorize or identify the source of the log
* @param message The message to be logged (can be any object, will be converted to string)
* @param throwable Optional exception or throwable to be logged alongside the message
*/
fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?)
/**
* Logs a message without a tag
*
* Convenience method that calls the main [performLog] with `tag` set to `null`
*
* @param level The severity level of the log message
* @param message The message to be logged
* @param throwable Optional exception or throwable to be logged
*/
fun performLog(level: LogLevel, message: Any, throwable: Throwable?) = performLog(level, null, message, throwable)
/**
* Logs a message with lazy evaluation of the message content
*
* The [messageBuilder] lambda will only be executed if the message is actually logged.
* This is useful for expensive message construction that should be avoided when the
* message would be filtered out.
*
* This method should be overridden in logger implementations that support lazy evaluation
* (like [dev.inmo.kslog.common.filter.FilterKSLog]).
*
* @param level The severity level of the log message
* @param tag Optional tag to categorize the log
* @param throwable Optional exception or throwable to be logged
* @param messageBuilder Lambda that builds the message only when needed
*/
fun performLog(
level: LogLevel,
tag: String?,
throwable: Throwable?,
messageBuilder: () -> Any
) = performLog(level, tag, messageBuilder(), throwable)
/**
* Suspendable variant of [performLog] with lazy message evaluation
*
* Similar to the non-suspending [performLog] with [messageBuilder], but allows the
* message builder to be a suspending function. This enables logging with messages
* that require async operations to construct.
*
* By default, executes the suspending [messageBuilder] and calls the regular [performLog].
*
* @param level The severity level of the log message
* @param tag Optional tag to categorize the log
* @param throwable Optional exception or throwable to be logged
* @param messageBuilder Suspending lambda that builds the message only when needed
*/
suspend fun performLogS(
level: LogLevel,
tag: String?,
@@ -32,6 +113,16 @@ interface KSLog {
companion object : KSLog {
private var defaultLogger: KSLog? = null
/**
* Default logger instance used when calling logging extensions without an explicit receiver
*
* If not explicitly set, a default logger with tag "app" will be created automatically.
* You can customize this by setting your own logger implementation.
*
* @see setDefaultKSLog
* @see addDefaultKSLog
*/
var default: KSLog
get() {
return defaultLogger ?: KSLog("app").also {
@@ -59,16 +150,53 @@ interface KSLog {
}
/**
* Creates a [CallbackKSLog] by invoking a [KSLog] instance with a callback function
*
* This operator allows convenient logger creation syntax:
* ```kotlin
* val logger = KSLog { level, tag, message, throwable ->
* // Custom logging logic
* }
* ```
*
* @param performLogCallback The callback function to handle log messages
* @return A new [CallbackKSLog] instance
*/
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
/**
* Simple logging implementation that uses `println` to output formatted log messages
*
* Uses [defaultMessageFormatter] to format messages before outputting to standard output.
* This is used as the default logging backend for Native and WASM platforms.
*
* @see defaultMessageFormatter
*/
internal val printlnLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
println(defaultMessageFormatter(l, t, m, e))
}
/**
* Creates a [DefaultKSLog] logger with the specified default tag
*
* @param defaultTag The default tag to use for all log messages from this logger
* @return A new [DefaultKSLog] instance
*/
fun KSLog(
defaultTag: String,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog = DefaultKSLog(defaultTag)
/**
* Creates a [DefaultKSLog] logger with a custom message formatter
*
* @param defaultTag The default tag to use for all log messages
* @param messageFormatter Custom formatter for converting log parameters to strings
* @return A new [DefaultKSLog] instance
*/
fun KSLog(
defaultTag: String,
messageFormatter: MessageFormatter
): KSLog = DefaultKSLog(
defaultTag,
messageFormatter
@@ -79,23 +207,45 @@ fun KSLog(
defaultTag: String,
filter: MessageFilter,
messageFormatter: MessageFormatter = defaultMessageFormatter
): KSLog = DefaultKSLog(
): KSLog = KSLog (
defaultTag,
filter,
messageFormatter
)
).filtered(filter)
/**
* Creates a filtered [KSLog] that only logs messages at specific levels
*
* Builds a logger that will only process log messages whose level is included in the [levels] collection.
* All other log levels will be filtered out.
*
* @param defaultTag The default tag to use for all log messages
* @param levels Collection of log levels that should be logged
* @param messageFormatter Custom formatter for converting log parameters to strings (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
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
}
}
/**
* Creates a filtered [KSLog] that only logs messages at the specified levels
*
* Convenience overload that accepts individual log levels as parameters.
*
* @param defaultTag The default tag to use for all log messages
* @param firstLevel First log level to include
* @param secondLevel Second log level to include
* @param otherLevels Additional log levels to include
* @param messageFormatter Custom formatter for converting log parameters to strings (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
fun KSLog(
defaultTag: String,
firstLevel: LogLevel,
@@ -104,6 +254,18 @@ fun KSLog(
messageFormatter: MessageFormatter = defaultMessageFormatter,
): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter)
/**
* Creates a filtered [KSLog] that only logs messages at or above a minimum severity level
*
* Uses the ordinal values of [LogLevel] enum to determine which messages to log.
* For example, if [minLoggingLevel] is INFO, then INFO, WARNING, ERROR, and ASSERT will be logged,
* while TRACE, DEBUG, and VERBOSE will be filtered out.
*
* @param defaultTag The default tag to use for all log messages
* @param minLoggingLevel Minimum log level to include (inclusive)
* @param messageFormatter Custom formatter for converting log parameters to strings (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
fun KSLog(
defaultTag: String,
minLoggingLevel: LogLevel,
@@ -115,5 +277,24 @@ fun KSLog(
minLoggingLevel.ordinal <= l.ordinal
}
/**
* Sets the [KSLog.default] logger to a new instance
*
* This replaces the current default logger completely.
*
* @param newDefault The new default logger to use
*/
fun setDefaultKSLog(newDefault: KSLog) { KSLog.default = newDefault }
fun addDefaultKSLog(newDefault: KSLog) { KSLog.default = KSLog.default + newDefault }
/**
* Adds an additional logger to the [KSLog.default] logger chain
*
* Uses the [plus] operator to combine the current default logger with [newDefault],
* so that log messages will be sent to both loggers.
*
* @param newDefault Additional logger to add to the default logger chain
* @see dev.inmo.kslog.common.utils.plus
*/
fun addDefaultKSLog(newDefault: KSLog) {
KSLog.default += newDefault
}

View File

@@ -1,8 +1,43 @@
package dev.inmo.kslog.common
/**
* Function type for formatting log messages
*
* @param l The log level
* @param t Optional tag for the log message
* @param m The message object to be logged
* @param Throwable Optional exception/throwable to be logged
* @return Formatted string representation of the log message
*/
typealias MessageFormatter = (l: LogLevel, t: String?, m: Any, Throwable?) -> String
@Suppress("NOTHING_TO_INLINE")
/**
* Helper function to create a [MessageFormatter] from a lambda
*/
inline fun MessageFormatter(noinline formatter: MessageFormatter) = formatter
/**
* Function type for filtering log messages
*
* @param l The log level
* @param t Optional tag for the log message
* @param Throwable Optional exception/throwable associated with the log
* @return `true` if the message should be logged, `false` to filter it out
*/
typealias MessageFilter = (l: LogLevel, t: String?, Throwable?) -> Boolean
/**
* Default message formatter that formats logs as: `[LEVEL] tag - message`
*
* Example output: `[LogLevel.INFO] MyTag - Hello world`
*/
val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] ${t ?.let { "$it " } ?: ""}- $m" }
/**
* Message formatter that includes stack trace of exceptions in the output
*
* Formats logs as: `[LEVEL] tag - message: stacktrace`
*
* Example output: `[LogLevel.ERROR] MyTag - Error occurred: java.lang.Exception: ...`
*/
val defaultMessageFormatterWithErrorPrint: MessageFormatter = { l, t, m, e -> "[$l] ${t ?.let { "$it " } ?: ""}- $m${e ?.let { ": ${it.stackTraceToString()}" } ?: ""}" }

View File

@@ -0,0 +1,21 @@
package dev.inmo.kslog.common
/**
* Platform-specific default logging implementation
*
* This is an `expect` declaration that provides platform-specific logging behavior:
* - **Android**: Uses `android.util.Log` (Log.d, Log.i, Log.w, Log.e, etc.)
* - **JVM**: Uses `java.util.logging.Logger`
* - **JS**: Uses browser `console` (console.debug, console.info, console.warn, console.error)
* - **Native/WASM**: Uses `println` for output
*
* This lambda is used by [DefaultKSLog] as the default logging backend when no custom
* logging function is provided.
*
* **Warning**: This is a global mutable variable. Changing it will affect all loggers
* that use the default platform logger. It's primarily used by [KSLog.default].
*
* @see DefaultKSLog
* @see KSLog.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,23 @@ package dev.inmo.kslog.common.filter
import dev.inmo.kslog.common.*
/**
* A logger that filters messages before passing them to a fallback logger
*
* This logger implementation applies a [messageFilter] predicate to all incoming log requests.
* Only when the filter returns `true` will the message be passed to the [fallbackLogger].
*
* This enables:
* - Log level filtering (e.g., only log ERROR and above)
* - Tag-based filtering (e.g., only log from specific components)
* - Conditional logging based on exception presence
* - Lazy message evaluation - messages are only constructed if they pass the filter
*
* @param fallbackLogger The underlying logger that will receive filtered messages
* @param messageFilter Predicate function that determines which messages to log
*
* @see filtered Extension function for convenient filter creation
*/
class FilterKSLog(
private val fallbackLogger: KSLog,
private val messageFilter: MessageFilter

View File

@@ -3,6 +3,23 @@ package dev.inmo.kslog.common.filter
import dev.inmo.kslog.common.KSLog
import dev.inmo.kslog.common.MessageFilter
/**
* Creates a [FilterKSLog] that wraps this logger with a message filter
*
* This extension function provides a convenient way to add filtering to any existing logger.
* The resulting logger will only pass messages to this logger when the [filter] returns `true`.
*
* Example:
* ```kotlin
* val logger = KSLog("app").filtered { level, tag, throwable ->
* level.ordinal >= LogLevel.INFO.ordinal // Only log INFO and above
* }
* ```
*
* @param filter Predicate function that receives (level, tag, throwable) and returns whether to log
* @return A new [FilterKSLog] instance wrapping this logger
* @see FilterKSLog
*/
fun KSLog.filtered(
filter: MessageFilter
) = FilterKSLog(this, filter)

View File

@@ -3,6 +3,27 @@ package dev.inmo.kslog.common.typed
import dev.inmo.kslog.common.*
import kotlin.reflect.KClass
/**
* A logger that routes messages to different loggers based on the message type
*
* This logger uses the Kotlin class ([KClass]) of the log message to determine which logger to use.
* This enables type-based routing of log messages, allowing different message types to be
* handled by different loggers.
*
* The routing works as follows:
* 1. Extract the [KClass] from the incoming message object
* 2. Look up the class in [typedLoggers] map
* 3. If found, use that logger
* 4. If not found, fall back to the logger with `null` key (if it exists)
* 5. If no default logger exists, skip logging
*
* Example use case: Route structured log events to different destinations based on their type.
*
* @param typedLoggers Map from message class to logger. Use `null` key for the default/fallback logger
*
* @see TypedKSLogBuilder Builder for creating typed loggers
* @see buildTypedLogger DSL function for convenient creation
*/
class TypedKSLog(
private val typedLoggers: Map<KClass<*>?, KSLog>
) : KSLog {

View File

@@ -3,6 +3,16 @@ package dev.inmo.kslog.common.typed
import dev.inmo.kslog.common.*
import kotlin.reflect.KClass
/**
* Builder for creating [TypedKSLog] instances with a fluent API
*
* Provides convenient methods for configuring type-based routing of log messages.
* Supports both explicit [KClass] specifications and reified type parameters.
*
* @param preset Optional initial map of type-to-logger associations to start with
*
* @see buildTypedLogger DSL function for convenient usage
*/
class TypedKSLogBuilder(
private val preset: Map<KClass<*>?, KSLog> = emptyMap()
) {
@@ -10,18 +20,81 @@ class TypedKSLogBuilder(
putAll(preset)
}
/**
* Associates a specific class with a logger
*
* @param kClass The class to route, or `null` for the default/fallback logger
* @param with The logger to use for this class
*/
fun on(kClass: KClass<*>?, with: KSLog) = loggers.put(kClass, with)
/**
* Associates a specific class with a callback-based logger
*
* @param kClass The class to route, or `null` for the default/fallback logger
* @param with The callback function to handle logs for this class
*/
fun on(kClass: KClass<*>?, with: SimpleKSLogCallback) = loggers.put(kClass, CallbackKSLog(with))
/**
* Sets the default/fallback logger for messages of unregistered types
*
* @param with The logger to use as default
*/
fun default(with: KSLog) = on(null, with)
/**
* Sets the default/fallback logger using a callback function
*
* @param with The callback function to handle logs from unregistered types
*/
fun default(with: SimpleKSLogCallback) = on(null, with)
/**
* Associates a specific type with a logger using reified type parameter
*
* Example: `on<MyEvent>(customLogger)`
*
* @param T The type to route
* @param with The logger to use for this type
*/
inline fun <reified T: Any> on(with: KSLog) = on(T::class, with)
/**
* Associates a specific type with a callback-based logger using reified type parameter
*
* Example: `on<MyEvent> { level, tag, message, error -> ... }`
*
* @param T The type to route
* @param with The callback function to handle logs for this type
*/
inline fun <reified T: Any> on(noinline with: SimpleKSLogCallback) = on(T::class, with)
/**
* Builds the [TypedKSLog] instance with the configured type-to-logger associations
*/
fun build() = TypedKSLog(loggers.toMap())
}
/**
* DSL function for building a [TypedKSLog] with a fluent configuration block
*
* Provides a convenient way to create typed loggers with type-to-logger associations.
*
* Example:
* ```kotlin
* val logger = buildTypedLogger {
* on<ErrorEvent>(errorLogger)
* on<WarningEvent>(warningLogger)
* default(defaultLogger)
* }
* ```
*
* @param preset Optional initial map of type-to-logger associations
* @param block Configuration block for specifying type-to-logger associations
* @return A new [TypedKSLog] instance
* @see TypedKSLogBuilder
*/
inline fun buildTypedLogger(
preset: Map<KClass<*>?, KSLog> = emptyMap(),
block: TypedKSLogBuilder.() -> Unit

View File

@@ -3,6 +3,27 @@ package dev.inmo.kslog.common.utils
import dev.inmo.kslog.common.CallbackKSLog
import dev.inmo.kslog.common.KSLog
/**
* Combines two loggers into one that sends messages to both
*
* Creates a new logger that will invoke [performLog] on both this logger and the [other] logger
* for every log message. Both loggers will be called even if one fails.
*
* Error handling:
* - If this logger throws an exception, it will be rethrown after attempting to log to [other]
* - If [other] throws an exception, it will also be rethrown
* - If both throw exceptions, both will be rethrown (first this logger's, then other's)
*
* Example:
* ```kotlin
* val combinedLogger = consoleLogger + fileLogger
* combinedLogger.info("Message") // Logs to both console and file
* ```
*
* @param other The second logger to combine with this one
* @return A new [CallbackKSLog] that logs to both loggers
* @see addDefaultKSLog Uses this operator to add loggers to the default logger
*/
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,63 @@
package dev.inmo.kslog.common
import kotlin.js.Console
/**
* Extended Console interface that includes additional console methods
* not present in Kotlin's standard Console interface
*
* Provides access to browser/Node.js console methods like `debug`, `trace`, and `assert`.
*/
external interface ExtendedConsole : Console {
/**
* Outputs a stack trace to the console
*/
fun trace()
/**
* Outputs a debug message to the console
*
* @param o Objects to output
*/
fun debug(vararg o: Any?)
/**
* Writes an error message to the console if the assertion is false
*
* @param assertion Boolean condition to test
* @param o Objects to output if assertion is false
*/
fun assert(assertion: Boolean, vararg o: Any?)
}
/**
* Extension function to output debug messages to the console
*
* Maps to the browser's `console.debug()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static)
*
* @param args Objects to output
*/
fun Console.debug(vararg args: Any?) = unsafeCast<ExtendedConsole>().debug(*args)
/**
* Extension function to write an error message if assertion fails
*
* Maps to the browser's `console.assert()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static)
*
* @param assertion Boolean condition to test
* @param args Objects to output if assertion is false
*/
fun Console.assert(assertion: Boolean, vararg args: Any?) = unsafeCast<ExtendedConsole>().assert(assertion, *args)
/**
* Extension function to output a stack trace to the console
*
* Maps to the browser's `console.trace()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static)
*/
fun Console.trace() = unsafeCast<ExtendedConsole>().trace()

View File

@@ -0,0 +1,37 @@
package dev.inmo.kslog.common
/**
* JavaScript platform implementation of the default logger
*
* Uses browser/Node.js `console` API as the logging backend, mapping KSLog levels
* to console methods:
* - [LogLevel.TRACE] → console.trace() + console.debug()
* - [LogLevel.DEBUG] → console.debug()
* - [LogLevel.VERBOSE] → console.info()
* - [LogLevel.INFO] → console.info()
* - [LogLevel.WARNING] → console.warn()
* - [LogLevel.ERROR] → console.error()
* - [LogLevel.ASSERT] → console.error()
*
* Logs can be viewed in the browser's Developer Tools console or Node.js console output.
*
* **Note**: The tag parameter is ignored in JS implementation as console methods
* don't support tagging natively.
*/
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,37 @@ import dev.inmo.kslog.common.filter.filtered
import java.util.logging.Level
import java.util.logging.Logger
private val defaultKSLogLogger by lazy {
/**
* Default Java Logger instance used by KSLog on JVM platform
*
* Initialized lazily with the name "KSLog"
*/
internal val defaultKSLogLogger by lazy {
Logger.getLogger("KSLog")
}
private fun Logger.doLog(
l: LogLevel, t: String, m: String, e: Throwable?
/**
* Extension function to log with KSLog levels using Java Logger
*
* Maps KSLog [LogLevel] to Java [Level]:
* - [LogLevel.TRACE] → [Level.FINEST]
* - [LogLevel.DEBUG] → [Level.FINER]
* - [LogLevel.VERBOSE] → [Level.FINE]
* - [LogLevel.INFO] → [Level.INFO]
* - [LogLevel.WARNING] → [Level.WARNING]
* - [LogLevel.ERROR] → [Level.SEVERE]
* - [LogLevel.ASSERT] → [Level.SEVERE]
*
* @param l KSLog log level
* @param m Message string
* @param e Optional throwable
*/
internal fun Logger.doLog(
l: LogLevel, 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 +44,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(
@@ -34,28 +54,56 @@ fun KSLog(
) = KSLog { l, t, m, e ->
if (!filter(l, t, e)) return@KSLog
val text = messageFormatter(l,t ?: defaultTag,m.toString(),e)
logger.doLog(l, t ?: defaultTag, text, e)
logger.doLog(l, text, e)
}
/**
* Creates a KSLog that uses a specific Java [Logger] instance
*
* @param defaultTag Default tag to use when tag is not specified
* @param logger The Java Logger instance to use for logging
* @param messageFormatter Formatter for log messages (defaults to [defaultMessageFormatter])
* @return A new [CallbackKSLog] instance wrapping the Java logger
*/
fun KSLog(
defaultTag: String,
logger: Logger,
messageFormatter: MessageFormatter = defaultMessageFormatter
) = KSLog { l, t, m, e ->
val text = messageFormatter(l,t ?: defaultTag,m.toString(),e)
logger.doLog(l, t ?: defaultTag, text, e)
logger.doLog(l, text, e)
}
/**
* Creates a filtered KSLog using a Java [Logger] that only logs specific levels
*
* @param defaultTag Default tag to use when tag is not specified
* @param logger The Java Logger instance to use for logging
* @param levels Collection of log levels to include
* @param messageFormatter Formatter for log messages (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
fun KSLog(
defaultTag: String,
logger: Logger,
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 }
}
/**
* Creates a filtered KSLog using a Java [Logger] with specific log levels
*
* @param defaultTag Default tag to use when tag is not specified
* @param logger The Java Logger instance to use for logging
* @param firstLevel First log level to include
* @param secondLevel Second log level to include
* @param otherLevels Additional log levels to include
* @param messageFormatter Formatter for log messages (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
fun KSLog(
defaultTag: String,
logger: Logger,
@@ -65,6 +113,17 @@ fun KSLog(
messageFormatter: MessageFormatter = defaultMessageFormatter,
): KSLog = KSLog (defaultTag, logger, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter)
/**
* Creates a filtered KSLog using a Java [Logger] with a minimum log level
*
* Only logs messages at or above the specified minimum level.
*
* @param defaultTag Default tag to use when tag is not specified
* @param logger The Java Logger instance to use for logging
* @param minLoggingLevel Minimum log level to include (defaults to TRACE - the first level)
* @param messageFormatter Formatter for log messages (defaults to [defaultMessageFormatter])
* @return A new filtered [KSLog] instance
*/
fun KSLog(
defaultTag: String,
logger: Logger,

View File

@@ -0,0 +1,13 @@
package dev.inmo.kslog.common
/**
* JVM platform implementation of the default logger
*
* Uses `[java.util.logging.Logger]` as the logging backend, mapping KSLog levels
* to Java logging levels.
*
* @see defaultKSLogLogger
*/
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
defaultKSLogLogger.doLog(l, 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,16 +0,0 @@
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 ->
val messageString = m.toString()
when(l) {
LogLevel.DEBUG -> Log.d(t, messageString, e)
LogLevel.VERBOSE -> Log.v(t, messageString, e)
LogLevel.INFO -> Log.i(t, messageString, e)
LogLevel.WARNING -> Log.w(t, messageString, e)
LogLevel.ERROR -> Log.e(t, messageString, e)
LogLevel.ASSERT -> Log.wtf(t, messageString, 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

@@ -0,0 +1,12 @@
package dev.inmo.kslog.common
/**
* Native platform implementation of the default logger
*
* Uses [printlnLogging] which formats and outputs logs using `[println]`.
* Logs are written to standard output.
*
* @see printlnLogging
*/
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,11 @@
package dev.inmo.kslog.common
/**
* WebAssembly JavaScript platform implementation of the default logger
*
* Uses [printlnLogging] which formats and outputs logs using `[println]`.
*
* @see printlnLogging
*/
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit =
printlnLogging