mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2025-11-12 17:30:15 +00:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f92a3e614 | |||
| 3c4e59ddc2 | |||
| 461bc92966 | |||
| 8c0968ba86 | |||
| 526de46a98 | |||
| 0af8c78e37 | |||
| 6840598e04 | |||
| 7a2d070ee3 | |||
| 92651d3ba6 | |||
| b8c72f1131 | |||
| 9b92fa29f4 | |||
| 42ced6edd2 | |||
| dd3e4c4c2a | |||
| f528909915 | |||
| b3919c8439 | |||
| d1dd159e36 | |||
| 3db55982e9 | |||
| 8e477b1056 | |||
| 480d2c8132 | |||
| a2a73dfe83 | |||
| 4528918347 | |||
|
|
9ef93724ad | ||
| dccbd13788 | |||
| 8bb34d6842 | |||
| cff3f71de7 | |||
| aab0ac064f | |||
| d2909ed5f0 | |||
| 81eba88ce9 | |||
| a73f0d132c | |||
| bd87184f81 | |||
| 7228e81344 | |||
| ac828b1af7 | |||
| a8c85b9614 | |||
| 98fbf43d4d | |||
| ef8a3e1500 | |||
| 3edbb78d56 | |||
| 663395ccbe | |||
| ecd2b08c69 | |||
| f5e50d00a2 | |||
| a1784dc6af | |||
| 4d6410c870 | |||
| 3a4035f1a6 | |||
| 86bf9468ba | |||
| 24adeef67b | |||
| 4823df5c6f | |||
| 2d397e9b12 | |||
| 37a0fceb56 | |||
| 0860d6cacc | |||
| d9863ded5a | |||
| 48a265e3d5 | |||
| 30cdbea2c9 | |||
| b19639e8a1 | |||
| 447e4fe5ac | |||
| 30d82ebda6 | |||
| 0b7b408b06 | |||
| ea43501a03 | |||
| 0348756729 | |||
| 81b32b0119 | |||
| 7a8bd035f5 | |||
| 34a7c9624d | |||
| fb0f61bb15 | |||
| 48eeb6660e | |||
| ff14fd5e7c | |||
| aa7bd6179a | |||
| ef72365505 | |||
| c0a10436be | |||
| a3170786a7 | |||
| d60e35f1e9 | |||
| bed00407fb | |||
| f326d9070a | |||
| b4c454141e | |||
| 1a589c675e | |||
| d25a73df3d | |||
| 333cb690a1 | |||
| a3e6ccf973 | |||
| 9ce62e13f5 | |||
| e88df8db99 | |||
| 8613f350e3 | |||
| 7fbf80a52a | |||
| 00da37e060 | |||
| a779791a00 | |||
| 03cc000306 | |||
| 875d2d723e | |||
| 01722311e6 | |||
| 9b994de857 | |||
| a170bbaa5c | |||
| 7b8d72e9c0 | |||
| 0237ec56c5 | |||
| bef9e0c550 | |||
| d7eb0093d8 | |||
| deba12ed5d | |||
| f608cf4bef | |||
|
|
4a656d2d90 | ||
| c730f49fbd | |||
| 2a36f64b51 | |||
| 604ef1b347 | |||
| dc50977c9a | |||
| 7c0650e2df | |||
| 387ca9097c |
2
.github/workflows/kdocs.yml
vendored
2
.github/workflows/kdocs.yml
vendored
@@ -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
|
||||
|
||||
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@@ -7,7 +7,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
java-version: 17
|
||||
- name: Rewrite version
|
||||
run: |
|
||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -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
|
||||
|
||||
92
CHANGELOG.md
92
CHANGELOG.md
@@ -1,5 +1,97 @@
|
||||
# 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`
|
||||
|
||||
@@ -10,7 +10,7 @@ It is simple and easy-to-use tool for logging on the most popular platforms in K
|
||||

|
||||
|
||||
[](https://insanusmokrassar.github.io/KSLog/)
|
||||
[](https://bookstack.inmo.dev/books/kslog)
|
||||
[](https://docs.inmo.dev/kslog/index.html)
|
||||
|
||||
By default, KSLog is using built-in tools for logging on each supported platform:
|
||||
|
||||
|
||||
57
build.gradle
57
build.gradle
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ org.gradle.jvmargs=-Xmx512m
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=1.1.0
|
||||
android_code_version=19
|
||||
version=1.5.2
|
||||
android_code_version=39
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "1.8.20"
|
||||
kotlin-gradle-plugin = "7.3.1"
|
||||
kotlin = "2.2.21"
|
||||
kotlin-gradle-plugin = "8.12.+"
|
||||
|
||||
dokka = "1.8.10"
|
||||
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.1"
|
||||
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" }
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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
|
||||
|
||||
121
publish.gradle
121
publish.gradle
@@ -1,7 +1,8 @@
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
archiveClassifier = 'javadoc'
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -19,70 +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"
|
||||
}
|
||||
|
||||
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')
|
||||
}
|
||||
|
||||
}
|
||||
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('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||
maven {
|
||||
name = "Gitea"
|
||||
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Authorization"
|
||||
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||
}
|
||||
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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')
|
||||
}
|
||||
|
||||
}
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"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
6
renovate.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
rootProject.name = 'kslog'
|
||||
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,17 +150,50 @@ 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,
|
||||
): KSLog = TagLogger(defaultTag)
|
||||
): 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
|
||||
@@ -88,17 +212,40 @@ fun KSLog(
|
||||
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,
|
||||
@@ -107,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,
|
||||
@@ -118,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
|
||||
}
|
||||
|
||||
@@ -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()}" } ?: ""}" }
|
||||
|
||||
@@ -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
|
||||
@@ -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?) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
63
src/jsMain/kotlin/ExtendedConsole.kt
Normal file
63
src/jsMain/kotlin/ExtendedConsole.kt
Normal 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()
|
||||
37
src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
37
src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
13
src/jvmMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
13
src/jvmMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal 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)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
@@ -1 +0,0 @@
|
||||
<manifest package="dev.inmo.kslog"/>
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
12
src/nativeMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
12
src/nativeMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal 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
|
||||
@@ -1,4 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit
|
||||
get() = printlnLogging
|
||||
11
src/wasmJsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
11
src/wasmJsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal 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
|
||||
Reference in New Issue
Block a user