Skip to content

Commit

Permalink
4.x changes (#269)
Browse files Browse the repository at this point in the history
* Add Level to common
* Add Marker to common
* Move MarkerFactory to common
* add sfl4j methods to logger
* rename package mu to io.github.oshai
* update kotlin to 1.8.0
* change slf4j dep for compile only
* move methods to Slf4jExtensions.kt
* add jul activate with -Dkotlin-logging-to-jul
* add jul impl
* add jul test
* remove jcenter
* fix windows test
* add github-release-4.x to github actions
* change package to io.github.oshai
* change group (coordinate) to io.github.oshai
* change pom name
* change maven url
* change url according to https://central.sonatype.org/publish/publish-gradle/#review-requirements
* bump version to 4.0.0-beta-10
  • Loading branch information
oshai authored Feb 10, 2023
1 parent 0d571f3 commit e19a728
Show file tree
Hide file tree
Showing 80 changed files with 2,121 additions and 747 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- github-release
- github-release-4.x

jobs:
release:
Expand All @@ -16,12 +17,12 @@ jobs:
with:
java-version: 11
- name: Publish
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon --no-parallel --stacktrace -DSONATYPE_USERNAME=$SONATYPE_USERNAME -DSONATYPE_PASSWORD=$SONATYPE_PASSWORD -DGPG_PRIVATE_PASSWORD=$GPG_PRIVATE_PASSWORD -DGPG_PRIVATE_KEY=$GPG_PRIVATE_KEY
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon --no-parallel --stacktrace -DSONATYPE_USERNAME_2=$SONATYPE_USERNAME_2 -DSONATYPE_PASSWORD_2=$SONATYPE_PASSWORD_2 -DGPG_PRIVATE_PASSWORD=$GPG_PRIVATE_PASSWORD -DGPG_PRIVATE_KEY=$GPG_PRIVATE_KEY
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME_2: ${{ secrets.SONATYPE_USERNAME_2 }}
SONATYPE_PASSWORD_2: ${{ secrets.SONATYPE_PASSWORD_2 }}
SONATYPE_REPOSITORY_ID: ${{ needs.create_staging_repository.outputs.repository_id }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PRIVATE_PASSWORD: ${{ secrets.GPG_PRIVATE_PASSWORD }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD_2 }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME_2 }}
18 changes: 13 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ plugins {

apply("versions.gradle.kts")

group = "io.github.microutils"
version = "3.0.6"
group = "io.github.oshai"
version = "4.0.0-beta-10"

repositories {
mavenCentral()
}

nexusPublishing {
repositories {
sonatype()
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(System.getenv("SONATYPE_USERNAME_2")) // defaults to project.properties["myNexusUsername"]
password.set(System.getenv("SONATYPE_PASSWORD_2")) // defaults to project.properties["myNexusPassword"]
}
}
}

Expand Down Expand Up @@ -82,7 +87,7 @@ kotlin {
}
val jvmMain by getting {
dependencies {
api("org.slf4j:slf4j-api:${extra["slf4j_version"]}")
compileOnly("org.slf4j:slf4j-api:${extra["slf4j_version"]}")
}
}
val jvmTest by getting {
Expand All @@ -94,6 +99,9 @@ kotlin {
implementation("org.apache.logging.log4j:log4j-api:${extra["log4j_version"]}")
implementation("org.apache.logging.log4j:log4j-core:${extra["log4j_version"]}")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:${extra["log4j_version"]}")
implementation("org.slf4j:slf4j-api:${extra["slf4j_version"]}")
// our jul test just forward the logs jul -> slf4j -> log4j
implementation("org.slf4j:jul-to-slf4j:${extra["slf4j_version"]}")
}
}
val jsMain by getting {}
Expand Down Expand Up @@ -218,6 +226,6 @@ detekt {

val jvmJar by tasks.getting(Jar::class) {
manifest {
attributes("Automatic-Module-Name" to "io.github.microutils.kotlinlogging")
attributes("Automatic-Module-Name" to "io.github.oshai.kotlinlogging")
}
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.stability.nowarn=true
kotlin.native.ignoreDisabledTargets=true
# workaround for https://github.com/gradle/gradle/issues/11412
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pluginManagement {
repositories {
gradlePluginPortal()
jcenter()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package mu
package io.github.oshai

public expect interface KLogger {

/**
* Return the name of this `Logger` instance.
* @return name of this logger instance
*/
public val name: String

/** Lazy add a log message if isTraceEnabled is true */
public fun trace(msg: () -> Any?)

Expand Down Expand Up @@ -33,34 +39,34 @@ public expect interface KLogger {
public fun error(t: Throwable?, msg: () -> Any?)

/** Lazy add a log message with a marker if isTraceEnabled is true */
public fun trace(marker: Marker?, msg: () -> Any?)
public fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?)

/** Lazy add a log message with a marker if isDebugEnabled is true */
public fun debug(marker: Marker?, msg: () -> Any?)
public fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?)

/** Lazy add a log message with a marker if isInfoEnabled is true */
public fun info(marker: Marker?, msg: () -> Any?)
public fun info(marker: io.github.oshai.Marker?, msg: () -> Any?)

/** Lazy add a log message with a marker if isWarnEnabled is true */
public fun warn(marker: Marker?, msg: () -> Any?)
public fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?)

/** Lazy add a log message with a marker if isErrorEnabled is true */
public fun error(marker: Marker?, msg: () -> Any?)
public fun error(marker: io.github.oshai.Marker?, msg: () -> Any?)

/** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */
public fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?)
public fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?)

/** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */
public fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?)
public fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?)

/** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */
public fun info(marker: Marker?, t: Throwable?, msg: () -> Any?)
public fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?)

/** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */
public fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?)
public fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?)

/** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */
public fun error(marker: Marker?, t: Throwable?, msg: () -> Any?)
public fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?)

/** Add a log message with all the supplied parameters along with method name */
public fun entry(vararg argArray: Any?)
Expand Down
7 changes: 7 additions & 0 deletions src/commonMain/kotlin/io/github/oshai/KMarkerFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.oshai

/** A platform independent factory to create markers. */
public object KMarkerFactory {

public fun getMarker(name: String): io.github.oshai.Marker = io.github.oshai.SimpleMarker(name)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu
package io.github.oshai

public expect object KotlinLogging {
/**
Expand All @@ -7,7 +7,7 @@ public expect object KotlinLogging {
* val logger = KotlinLogging.logger {}
* ```
*/
public fun logger(func: () -> Unit): KLogger
public fun logger(func: () -> Unit): io.github.oshai.KLogger

public fun logger(name: String): KLogger
public fun logger(name: String): io.github.oshai.KLogger
}
39 changes: 39 additions & 0 deletions src/commonMain/kotlin/io/github/oshai/Level.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.oshai

public enum class Level(private val levelInt: Int, private val levelStr: String) {
TRACE(io.github.oshai.Levels.TRACE_INT, "TRACE"),
DEBUG(io.github.oshai.Levels.DEBUG_INT, "DEBUG"),
INFO(io.github.oshai.Levels.INFO_INT, "INFO"),
WARN(io.github.oshai.Levels.WARN_INT, "WARN"),
ERROR(io.github.oshai.Levels.ERROR_INT, "ERROR"),
;

public fun toInt(): Int {
return levelInt
}

/** Returns the string representation of this Level. */
override fun toString(): String {
return levelStr
}
}

public object Levels {

public const val TRACE_INT: Int = 0
public const val DEBUG_INT: Int = 10
public const val INFO_INT: Int = 20
public const val WARN_INT: Int = 30
public const val ERROR_INT: Int = 40

public fun intToLevel(levelInt: Int): io.github.oshai.Level {
return when (levelInt) {
io.github.oshai.Levels.TRACE_INT -> io.github.oshai.Level.TRACE
io.github.oshai.Levels.DEBUG_INT -> io.github.oshai.Level.DEBUG
io.github.oshai.Levels.INFO_INT -> io.github.oshai.Level.INFO
io.github.oshai.Levels.WARN_INT -> io.github.oshai.Level.WARN
io.github.oshai.Levels.ERROR_INT -> io.github.oshai.Level.ERROR
else -> throw IllegalArgumentException("Level integer [$levelInt] not recognized.")
}
}
}
11 changes: 11 additions & 0 deletions src/commonMain/kotlin/io/github/oshai/Marker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.oshai

/** A platform independent marker to enrich log statements. */
public interface Marker {

public fun getName(): String
}

internal data class SimpleMarker(private val name: String) : io.github.oshai.Marker {
override fun getName(): String = this.name
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu.internal
package io.github.oshai.internal

@Suppress("NOTHING_TO_INLINE")
internal inline fun (() -> Any?).toStringSafe(): String {
Expand Down
7 changes: 0 additions & 7 deletions src/commonMain/kotlin/mu/KMarkerFactory.kt

This file was deleted.

7 changes: 0 additions & 7 deletions src/commonMain/kotlin/mu/Marker.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mu
package io.github.oshai

import kotlin.test.Test

class SimpleTest {
private val logger = KotlinLogging.logger {}
private val logger = io.github.oshai.KotlinLogging.logger {}

@Test
fun simpleTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu.internal
package io.github.oshai.internal

import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package mu
package io.github.oshai

public actual val DefaultAppender: Appender = OSLogAppender()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu
package io.github.oshai

import kotlinx.cinterop.ptr
import platform.darwin.OS_LOG_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu
package io.github.oshai

import kotlin.native.concurrent.AtomicReference
import platform.darwin.os_log_create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu
package io.github.oshai

public interface Appender {
public fun trace(message: Any?)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mu
package io.github.oshai

public object ConsoleOutputAppender : Appender {
public override fun trace(message: Any?): Unit = console.log(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package mu
package io.github.oshai

import mu.internal.toStringSafe
import io.github.oshai.internal.toStringSafe

public object DefaultMessageFormatter : Formatter {
public override fun formatMessage(
level: KotlinLoggingLevel,
loggerName: String,
msg: () -> Any?
): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}"
public override fun formatMessage(level: Level, loggerName: String, msg: () -> Any?): String =
"${level.name}: [$loggerName] ${msg.toStringSafe()}"

public override fun formatMessage(
level: KotlinLoggingLevel,
level: Level,
loggerName: String,
t: Throwable?,
msg: () -> Any?
): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}${t.throwableToString()}"

public override fun formatMessage(
level: KotlinLoggingLevel,
level: Level,
loggerName: String,
marker: Marker?,
msg: () -> Any?
): String = "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}"

public override fun formatMessage(
level: KotlinLoggingLevel,
level: Level,
loggerName: String,
marker: Marker?,
t: Throwable?,
Expand Down
14 changes: 14 additions & 0 deletions src/jsMain/kotlin/io/github/oshai/Formatter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.oshai

public interface Formatter {
public fun formatMessage(level: Level, loggerName: String, msg: () -> Any?): Any?
public fun formatMessage(level: Level, loggerName: String, t: Throwable?, msg: () -> Any?): Any?
public fun formatMessage(level: Level, loggerName: String, marker: Marker?, msg: () -> Any?): Any?
public fun formatMessage(
level: Level,
loggerName: String,
marker: Marker?,
t: Throwable?,
msg: () -> Any?
): Any?
}
Loading

0 comments on commit e19a728

Please sign in to comment.