Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/org.jetbrains.dokka-1.9.10
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai authored Dec 18, 2023
2 parents 6fc7439 + 1a2168b commit 0ba55f2
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 25 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ max_line_length = 150
; Tab indentation (no size specified)
indent_style = space
charset = utf-8
indent_size = 4

[*.yml]
indent_size = 2
3 changes: 2 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- github-release
- github-release-4.x
- github-release-5.x
- github-release-6.x

jobs:
release:
Expand All @@ -14,7 +15,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Configure JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ jobs:

- name: Restore native cache
id: cache-native
uses: actions/cache@v3.3.1
uses: actions/cache@v3.3.2
with:
path: |
scripts/build
key: ${{ runner.os }}-native-${{ hashFiles('./scripts/*') }}

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11

- name: Restore Gradle cache
id: cache-gradle
uses: actions/cache@v3.3.1
uses: actions/cache@v3.3.2
with:
path: |
~/.gradle/caches
Expand Down
13 changes: 12 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and [maven central](https://repo1.maven.org/maven2/io/github/oshai/kotlin-loggin

# Overview

The latest kotlin-logging version is 5.
The latest kotlin-logging version is 6.
It is the recommended version for new users and upgrades, as previous versions will require manual upgrade.

Version 4.x is **not recommended** to use (we jumped directly from v.3 to v.5).
Expand All @@ -31,6 +31,17 @@ In that sense it's a completely new dependency.

Below is a list of all versions, some history and note-worthy changes.

# Version 6

Released on: Dec 18, 2023.
Full change log:
[v.6](https://github.com/oshai/kotlin-logging/releases/tag/6.0.0).

Main changes are:

- Support kotlin version >= 1.9.
- Change to depend on KMP 1.9.

# Version 5

Released on: July 19, 2023.
Expand Down
24 changes: 17 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.jvm.tasks.Jar
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
kotlin("multiplatform") version "1.8.22"
kotlin("multiplatform") version "1.9.21"
id("org.jetbrains.dokka") version "1.9.10"
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
signing
id("io.gitlab.arturbosch.detekt") version "1.18.0"
id("com.android.library") version "7.4.2"
id("com.diffplug.spotless") version "6.20.0"
id("com.diffplug.spotless") version "6.23.3"
}


apply("versions.gradle.kts")

group = "io.github.oshai"
version = "5.1.1"
version = "6.0.1"

repositories {
gradlePluginPortal()
Expand All @@ -40,17 +42,25 @@ apply(plugin = "io.github.gradle-nexus.publish-plugin")

kotlin {
explicitApi()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
// kotlin compiler compatibility options
apiVersion.set(KotlinVersion.KOTLIN_1_9)
languageVersion.set(KotlinVersion.KOTLIN_1_9)

freeCompilerArgs.add("-Xexpect-actual-classes")
}

jvm {
compilations.all {
// kotlin compiler compatibility options
kotlinOptions {
apiVersion = "1.4"
languageVersion = "1.4"
jvmTarget = "1.8"
}
}
}
js(BOTH) {
js {
browser {
testTask {
useKarma {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
org.gradle.jvmargs=-Xmx2048m
# see https://kotlinlang.org/docs/whatsnew18.html#sourcedirectories
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.applyDefaultHierarchyTemplate=false
25 changes: 20 additions & 5 deletions src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,40 @@ public interface KLogger {
}

/** Lazy add a log message with throwable payload if isTraceEnabled is true */
public fun atTrace(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit =
public fun atTrace(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.TRACE, marker, block)

/** Lazy add a log message with throwable payload if isTraceEnabled is true */
public fun atTrace(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.TRACE, null, block)

/** Lazy add a log message with throwable payload if isDebugEnabled is true */
public fun atDebug(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit =
public fun atDebug(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.DEBUG, marker, block)

/** Lazy add a log message with throwable payload if isDebugEnabled is true */
public fun atDebug(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, null, block)

/** Lazy add a log message with throwable payload if isInfoEnabled is true */
public fun atInfo(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit =
public fun atInfo(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.INFO, marker, block)

/** Lazy add a log message with throwable payload if isInfoEnabled is true */
public fun atInfo(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, null, block)

/** Lazy add a log message with throwable payload if isWarnEnabled is true */
public fun atWarn(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit =
public fun atWarn(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.WARN, marker, block)

/** Lazy add a log message with throwable payload if isWarnEnabled is true */
public fun atWarn(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, null, block)

/** Lazy add a log message with throwable payload if isErrorEnabled is true */
public fun atError(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit =
public fun atError(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.ERROR, marker, block)

/** Lazy add a log message with throwable payload if isErrorEnabled is true */
public fun atError(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, null, block)

/** Lazy add a log message if level enabled */
public fun at(level: Level, marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:OptIn(ExperimentalForeignApi::class)

package io.github.oshai.kotlinlogging

import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ptr
import platform.darwin.OS_LOG_TYPE_DEBUG
import platform.darwin.OS_LOG_TYPE_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.oshai.kotlinlogging

import kotlin.native.concurrent.AtomicReference
import kotlin.concurrent.AtomicReference

public object KotlinLoggingConfiguration {
public var subsystem: AtomicReference<String?> = AtomicReference(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.oshai.kotlinlogging.internal
import io.github.oshai.kotlinlogging.DarwinKLogger
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
import kotlin.native.concurrent.AtomicReference
import kotlin.concurrent.AtomicReference
import platform.darwin.OS_LOG_DEFAULT
import platform.darwin.os_log_create

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,27 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
override fun atDebug(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.DEBUG, marker, block)

/** Lazy add a log message with throwable payload if isDebugEnabled is true */
override fun atDebug(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, null, block)

/** Lazy add a log message with throwable payload if isInfoEnabled is true */
override fun atInfo(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.INFO, marker, block)

/** Lazy add a log message with throwable payload if isInfoEnabled is true */
override fun atInfo(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, null, block)

/** Lazy add a log message with throwable payload if isWarnEnabled is true */
override fun atWarn(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.WARN, marker, block)

/** Lazy add a log message with throwable payload if isWarnEnabled is true */
override fun atWarn(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, null, block)

/** Lazy add a log message with throwable payload if isErrorEnabled is true */
override fun atError(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit =
at(Level.ERROR, marker, block)

/** Lazy add a log message with throwable payload if isErrorEnabled is true */
override fun atError(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, null, block)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ class ClassWithLoggingForLocationTesting {
logger.info { "log entry body" }
return logger.exit(null)
}

fun logFluentWithPayload() {
logger.atInfo {
message = "test"
payload = mapOf("key" to "value")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class LoggingWithLocationTest {
)
}

@Test
fun testFluentLoggingWithLocation() {
ClassWithLoggingForLocationTesting().logFluentWithPayload()
assertEquals(
"INFO ClassWithLoggingForLocationTesting.logFluentWithPayload(32) - test",
appenderWithWriter.writer.toString().trim()
)
}

@Test
fun testNullLoggingWithLocation() {
ClassWithLoggingForLocationTesting().logNull()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
@file:OptIn(ExperimentalForeignApi::class)

package io.github.oshai.kotlinlogging

import kotlinx.cinterop.ExperimentalForeignApi
import platform.posix.fprintf
import platform.posix.stderr

public object ConsoleOutputAppender : FormattingAppender() {
override fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?) {
if (loggingEvent.level == Level.ERROR) {
fprintf(stderr, "$formattedMessage\n")
fprintf(stderr, "%s\n", formattedMessage.toString())
} else {
println(formattedMessage)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.oshai.kotlinlogging

import kotlin.native.concurrent.AtomicReference
import kotlin.concurrent.AtomicReference

public expect val DefaultAppender: Appender

Expand Down
6 changes: 3 additions & 3 deletions versions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extra["slf4j_version"] = "2.0.6"
extra["slf4j_version"] = "2.0.9"
extra["coroutines_version"] = "1.6.4"
extra["log4j_version"] = "2.20.0"
extra["log4j_version"] = "2.22.0"
extra["mockito_version"] = "4.11.0"
extra["junit_version"] = "5.9.2"
extra["junit_version"] = "5.9.2"

0 comments on commit 0ba55f2

Please sign in to comment.