Skip to content

Commit

Permalink
Upgrade ktfmt to version 0.47
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewe committed Apr 1, 2024
1 parent 41dcc10 commit 6cf6b26
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ tasks {
spotless {
kotlin {
target("src/**/*.kt")
ktfmt("0.24").googleStyle()
ktfmt("0.47").googleStyle()
}
}

Expand Down
25 changes: 13 additions & 12 deletions src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface KLogger {

/**
* Return the name of this `Logger` instance.
*
* @return name of this logger instance
*/
public val name: String
Expand Down Expand Up @@ -378,7 +379,7 @@ public interface KLogger {
*/
@Deprecated(
"Use trace {} instead",
replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg1 \$arg2\"}"),
)
public fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO()

Expand All @@ -392,7 +393,7 @@ public interface KLogger {
*/
@Deprecated(
"Use trace {} instead",
replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arguments\"}"),
)
public fun trace(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO()

Expand Down Expand Up @@ -494,7 +495,7 @@ public interface KLogger {
*/
@Deprecated(
"Use debug {} instead",
replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg1 \$arg2\"}"),
)
public fun debug(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO()

Expand All @@ -508,7 +509,7 @@ public interface KLogger {
*/
@Deprecated(
"Use debug {} instead",
replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arguments\"}"),
)
public fun debug(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO()

Expand Down Expand Up @@ -609,7 +610,7 @@ public interface KLogger {
*/
@Deprecated(
"Use info {} instead",
replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg1 \$arg2\"}"),
)
public fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO()

Expand All @@ -623,7 +624,7 @@ public interface KLogger {
*/
@Deprecated(
"Use info {} instead",
replaceWith = ReplaceWith("info(marker) { \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("info(marker) { \"\$msg \$arguments\"}"),
)
public fun info(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO()

Expand Down Expand Up @@ -724,7 +725,7 @@ public interface KLogger {
*/
@Deprecated(
"Use warn {} instead",
replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg1 \$arg2\"}"),
)
public fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO()

Expand All @@ -738,7 +739,7 @@ public interface KLogger {
*/
@Deprecated(
"Use warn {} instead",
replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arguments\"}"),
)
public fun warn(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO()

Expand Down Expand Up @@ -817,7 +818,7 @@ public interface KLogger {
*/
@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker) { \"\$msg\"}")
replaceWith = ReplaceWith("error(marker) { \"\$msg\"}"),
)
public fun error(marker: Marker?, msg: String?): Unit = error(null as Throwable?, marker) { msg }

Expand All @@ -831,7 +832,7 @@ public interface KLogger {
*/
@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg \"}")
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg \"}"),
)
public fun error(marker: Marker?, msg: String?, arg: Any?): Unit = TODO()

Expand All @@ -846,7 +847,7 @@ public interface KLogger {
*/
@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg1 \$arg2\"}"),
)
public fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO()

Expand All @@ -860,7 +861,7 @@ public interface KLogger {
*/
@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("error(marker) { \"\$msg \$arguments\"}"),
)
public fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public object KotlinLogging {
* ```
* private val logger = KotlinLogging.logger("io.github.oshai.kotlinlogging.MyLogger")
* ```
*
* In most cases the name represents the package notation of the file that the logger is defined
* in.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class DarwinKLogger(override val name: String, override val underlyingLog
__dso_handle.ptr,
underlyingLogger,
level.toDarwinLevel(),
formattedMessage
formattedMessage,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal actual object KLoggerFactory {
name.contains(".") -> {
DarwinKLogger(
name,
os_log_create(name.substringBeforeLast("."), name.substringAfterLast("."))
os_log_create(name.substringBeforeLast("."), name.substringAfterLast(".")),
)
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface Appender {

public abstract class FormattingAppender : Appender {
public abstract fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?)

override fun log(loggingEvent: KLoggingEvent) {
KotlinLoggingConfiguration.formatter.formatMessage(loggingEvent).let {
logFormattedMessage(loggingEvent, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public data class KLoggingEvent(
level: Level,
marker: Marker?,
loggerName: String,
eventBuilder: KLoggingEventBuilder
eventBuilder: KLoggingEventBuilder,
) : this(
level,
marker,
loggerName,
eventBuilder.message,
eventBuilder.cause,
eventBuilder.payload
eventBuilder.payload,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ internal actual object KLoggerNameResolver {
// to search for the target declared field.
null
}
}
?: clazz
} ?: clazz
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean {
return isLoggingEnabledFor(underlyingLogger, level, marker)
}

override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) {
if (isLoggingEnabledFor(level, marker)) {
KLoggingEventBuilder().apply(block).run {
Expand All @@ -52,7 +53,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
private fun logWithPayload(
kLoggingEventBuilder: KLoggingEventBuilder,
level: Level,
marker: Marker?
marker: Marker?,
) {
val builder = underlyingLogger.atLevel(level.toSlf4j())
marker?.toSlf4j()?.let { builder.addMarker(it) }
Expand All @@ -67,15 +68,15 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
private fun logWithoutPayload(
kLoggingEventBuilder: KLoggingEventBuilder,
level: Level,
marker: Marker?
marker: Marker?,
) {
underlyingLogger.log(
marker?.toSlf4j(),
fqcn,
level.toSlf4j().toInt(),
kLoggingEventBuilder.message,
null,
kLoggingEventBuilder.cause
kLoggingEventBuilder.cause,
)
}

Expand Down Expand Up @@ -158,7 +159,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware
EventConstants.TRACE_INT,
tp.message,
arrayOf<Any?>(result),
tp.throwable
tp.throwable,
)
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) :
private fun logWithPayload(
kLoggingEventBuilder: KLoggingEventBuilder,
level: Level,
marker: Marker?
marker: Marker?,
) {
val builder = underlyingLogger.atLevel(level.toSlf4j())
marker?.toSlf4j()?.let { builder.addMarker(it) }
Expand All @@ -50,7 +50,7 @@ internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) :
private fun logWithoutPayload(
kLoggingEventBuilder: KLoggingEventBuilder,
level: Level,
marker: Marker?
marker: Marker?,
) {
val slf4jMarker = marker?.toSlf4j()
val message = kLoggingEventBuilder.message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class Slf4jLogger<T : Logger> : KLogger, DelegatingKLogger<T> {
protected fun isLoggingEnabledFor(
underlyingLogger: Logger,
level: Level,
marker: Marker?
marker: Marker?,
): Boolean {
return when (level) {
Level.TRACE -> underlyingLogger.isTraceEnabled(marker?.toSlf4j())
Expand Down Expand Up @@ -137,21 +137,21 @@ public abstract class Slf4jLogger<T : Logger> : KLogger, DelegatingKLogger<T> {

@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg\"}")
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg\"}"),
)
public override fun error(marker: Marker?, msg: String?, arg: Any?): Unit =
underlyingLogger.error(marker?.toSlf4j(), msg, arg)

@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg1 \$arg2\"}")
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg1 \$arg2\"}"),
)
public override fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit =
underlyingLogger.error(marker?.toSlf4j(), msg, arg1, arg2)

@Deprecated(
"Use error(marker){} instead",
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arguments\"}")
replaceWith = ReplaceWith("error(marker){ \"\$msg \$arguments\"}"),
)
public override fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit =
underlyingLogger.error(marker?.toSlf4j(), msg, *arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlin.reflect.KProperty

/**
* The JS way to define a logger without explicit name
*
* ```
* class MyClass {
* private val logger by KotlinLogging.logger()
Expand All @@ -21,8 +22,7 @@ private class LoggerDelegate : ReadOnlyProperty<Any?, KLogger> {
logger =
thisRef.asDynamic()?.constructor?.name.unsafeCast<String?>()?.let {
KotlinLogging.logger(it)
}
?: KotlinLogging.logger("root-logger")
} ?: KotlinLogging.logger("root-logger")
}
return logger
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public actual object KotlinLoggingConfiguration {
set(value) {
appender = value
}

@Deprecated("Use logLevel instead", ReplaceWith("logLevel"))
public var LOG_LEVEL: Level
get() = logLevel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.slf4j.MDC
public inline fun <T> withLoggingContext(
pair: Pair<String, String?>,
restorePrevious: Boolean = true,
body: () -> T
body: () -> T,
): T =
if (pair.second == null) {
body()
Expand All @@ -44,7 +44,7 @@ public inline fun <T> withLoggingContext(
public inline fun <T> withLoggingContext(
vararg pair: Pair<String, String?>,
restorePrevious: Boolean = true,
body: () -> T
body: () -> T,
): T {
val pairForMDC = pair.filter { it.second != null }
val cleanupCallbacks =
Expand Down Expand Up @@ -81,7 +81,7 @@ public inline fun <T> withLoggingContext(
public inline fun <T> withLoggingContext(
map: Map<String, String?>,
restorePrevious: Boolean = true,
body: () -> T
body: () -> T,
): T {
val cleanupCallbacks =
map.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.coroutines.slf4j.*
public suspend inline fun <T> withLoggingContextAsync(
pair: Pair<String, String?>,
restorePrevious: Boolean = true,
crossinline body: suspend () -> T
crossinline body: suspend () -> T,
): T =
withLoggingContext(pair, restorePrevious = restorePrevious) {
withContext(MDCContext()) { body() }
Expand All @@ -37,7 +37,7 @@ public suspend inline fun <T> withLoggingContextAsync(
public suspend inline fun <T> withLoggingContextAsync(
vararg pair: Pair<String, String?>,
restorePrevious: Boolean = true,
crossinline body: suspend () -> T
crossinline body: suspend () -> T,
): T =
withLoggingContext(*pair, restorePrevious = restorePrevious) {
withContext(MDCContext()) { body() }
Expand All @@ -59,7 +59,7 @@ public suspend inline fun <T> withLoggingContextAsync(
public suspend inline fun <T> withLoggingContextAsync(
map: Map<String, String?>,
restorePrevious: Boolean = true,
crossinline body: suspend () -> T
crossinline body: suspend () -> T,
): T =
withLoggingContext(map, restorePrevious = restorePrevious) {
withContext(MDCContext()) { body() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class JulLoggerWrapper(override val underlyingLogger: Logger) :
override fun at(
level: io.github.oshai.kotlinlogging.Level,
marker: Marker?, // marker is not supported in JUL
block: KLoggingEventBuilder.() -> Unit
block: KLoggingEventBuilder.() -> Unit,
) {
if (isLoggingEnabledFor(level, null)) {
KLoggingEventBuilder().apply(block).run {
Expand All @@ -27,7 +27,7 @@ internal class JulLoggerWrapper(override val underlyingLogger: Logger) :

override fun isLoggingEnabledFor(
level: io.github.oshai.kotlinlogging.Level,
marker: Marker?
marker: Marker?,
): Boolean {
return underlyingLogger.isLoggable(level.toJULLevel())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ data class AppenderWithWriter(
val pattern: String = "%-5p %c %marker - %m%n",
val writer: StringWriter = StringWriter(),
val appender: Appender =
WriterAppender.createAppender(newPatternLayout(pattern), null, writer, "writer", false, true)
WriterAppender.createAppender(newPatternLayout(pattern), null, writer, "writer", false, true),
)
Loading

0 comments on commit 6cf6b26

Please sign in to comment.