diff --git a/.github/workflows/deployment-ci.yml b/.github/workflows/deployment-ci.yml index 14c8f3492105..a0a01ee1e7fa 100644 --- a/.github/workflows/deployment-ci.yml +++ b/.github/workflows/deployment-ci.yml @@ -24,7 +24,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 @@ -49,7 +49,7 @@ jobs: with: fetch-depth: 0 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 diff --git a/.github/workflows/docs-ci.yml b/.github/workflows/docs-ci.yml index d939960e224a..4a2522ec3f1f 100644 --- a/.github/workflows/docs-ci.yml +++ b/.github/workflows/docs-ci.yml @@ -20,7 +20,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 71fc53572c32..260920e52585 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -6,6 +6,12 @@ repositories { mavenCentral() } +kotlin { + compilerOptions { + allWarningsAsErrors = true + } +} + dependencies { implementation(libs.bundles.pluginsForBuildSrc) } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 1d592ab41f00..fcc2c109d11f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -11,8 +11,6 @@ kotlin { api(libs.kotlinx.coroutines.core) api(libs.kotlinx.serialization.json) api(libs.kotlinx.datetime) - api(libs.kotlin.logging) - api(libs.ktor.client.core) compileOnly(projects.kspAnnotations) @@ -52,15 +50,15 @@ internal const val BUILD_CONFIG_GENERATED_COMMIT_HASH: String = "" internal const val BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH: String = "" */ buildConfig { - packageName("dev.kord.common") - className("BuildConfigGenerated") + packageName = "dev.kord.common" + className = "BuildConfigGenerated" useKotlinOutput { topLevelConstants = true internalVisibility = true } - buildConfigField("String", "BUILD_CONFIG_GENERATED_LIBRARY_VERSION", "\"$libraryVersion\"") - buildConfigField("String", "BUILD_CONFIG_GENERATED_COMMIT_HASH", "\"$commitHash\"") - buildConfigField("String", "BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", "\"$shortCommitHash\"") + buildConfigField("BUILD_CONFIG_GENERATED_LIBRARY_VERSION", libraryVersion) + buildConfigField("BUILD_CONFIG_GENERATED_COMMIT_HASH", commitHash) + buildConfigField("BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", shortCommitHash) } diff --git a/core/api/core.api b/core/api/core.api index 0a2cc7e9ba7a..daa638174d4c 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -102,6 +102,7 @@ public final class dev/kord/core/KordKt { public static final fun Kord (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun Kord$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun getKordLogger ()Lmu/KLogger; + public static final fun logCaughtThrowable (Ljava/lang/Throwable;)V } public abstract interface class dev/kord/core/KordObject { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 2e2553c88b82..8cbdb531e502 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -25,6 +25,16 @@ kotlin { api(libs.kord.cache.api) api(libs.kord.cache.map) + + implementation(libs.kotlin.logging) + + // TODO remove when kordLogger is removed + implementation(libs.kotlin.logging.old) + } + } + jvmMain { + dependencies { + implementation(libs.slf4j.api) } } jvmTest { diff --git a/core/src/commonMain/kotlin/Kord.kt b/core/src/commonMain/kotlin/Kord.kt index ae299b660e23..5cb81af8cf20 100644 --- a/core/src/commonMain/kotlin/Kord.kt +++ b/core/src/commonMain/kotlin/Kord.kt @@ -31,16 +31,21 @@ import dev.kord.rest.builder.interaction.* import dev.kord.rest.builder.user.CurrentUserModifyBuilder import dev.kord.rest.request.RestRequestException import dev.kord.rest.service.RestClient +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -import mu.KLogger -import mu.KotlinLogging import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.channels.Channel as CoroutineChannel -public val kordLogger: KLogger = KotlinLogging.logger { } +@Deprecated("Use your own logger instead, this will be removed in the future.", level = DeprecationLevel.WARNING) +public val kordLogger: mu.KLogger = mu.KotlinLogging.logger { } + +private val logger = KotlinLogging.logger { } + +@PublishedApi +internal fun logCaughtThrowable(throwable: Throwable): Unit = logger.catching(throwable) /** @@ -634,6 +639,6 @@ public inline fun Kord.on( ): Job = events.buffer(CoroutineChannel.UNLIMITED).filterIsInstance() .onEach { event -> - scope.launch { runCatching { consumer(event) }.onFailure { kordLogger.catching(it) } } + scope.launch { runCatching { consumer(event) }.onFailure(::logCaughtThrowable) } } .launchIn(scope) diff --git a/core/src/commonMain/kotlin/gateway/handler/DefaultGatewayEventInterceptor.kt b/core/src/commonMain/kotlin/gateway/handler/DefaultGatewayEventInterceptor.kt index 8725cfa03012..4960b214d791 100644 --- a/core/src/commonMain/kotlin/gateway/handler/DefaultGatewayEventInterceptor.kt +++ b/core/src/commonMain/kotlin/gateway/handler/DefaultGatewayEventInterceptor.kt @@ -3,7 +3,7 @@ package dev.kord.core.gateway.handler import dev.kord.common.annotation.KordPreview import dev.kord.core.Kord import dev.kord.core.gateway.ShardEvent -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import dev.kord.core.event.Event as CoreEvent private val logger = KotlinLogging.logger { } diff --git a/core/src/commonMain/kotlin/live/LiveKordEntity.kt b/core/src/commonMain/kotlin/live/LiveKordEntity.kt index 93e99ef7dd5b..f3920e19759d 100644 --- a/core/src/commonMain/kotlin/live/LiveKordEntity.kt +++ b/core/src/commonMain/kotlin/live/LiveKordEntity.kt @@ -6,7 +6,7 @@ import dev.kord.core.entity.KordEntity import dev.kord.core.event.Event import dev.kord.core.event.message.MessageUpdateEvent import dev.kord.core.event.message.ReactionAddEvent -import dev.kord.core.kordLogger +import dev.kord.core.logCaughtThrowable import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* @@ -53,5 +53,5 @@ public inline fun LiveKordEntity.on( noinline consumer: suspend (T) -> Unit ): Job = events.buffer(Channel.UNLIMITED).filterIsInstance().onEach { - runCatching { consumer(it) }.onFailure { kordLogger.catching(it) } - }.catch { kordLogger.catching(it) }.launchIn(scope) + runCatching { consumer(it) }.onFailure(::logCaughtThrowable) + }.catch { logCaughtThrowable(it) }.launchIn(scope) diff --git a/gateway/api/gateway.api b/gateway/api/gateway.api index a1353511dfd8..9596d77efeff 100644 --- a/gateway/api/gateway.api +++ b/gateway/api/gateway.api @@ -669,6 +669,7 @@ public final class dev/kord/gateway/GatewayConfigurationBuilder { public final class dev/kord/gateway/GatewayKt { public static final fun editPresence (Ldev/kord/gateway/Gateway;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getGatewayOnLogger ()Lmu/KLogger; + public static final fun logCaughtThrowable (Ljava/lang/Throwable;)V public static final fun requestGuildMembers (Ldev/kord/gateway/Gateway;Ldev/kord/common/entity/Snowflake;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow; public static final fun requestGuildMembers (Ldev/kord/gateway/Gateway;Ldev/kord/gateway/RequestGuildMembers;)Lkotlinx/coroutines/flow/Flow; public static synthetic fun requestGuildMembers$default (Ldev/kord/gateway/Gateway;Ldev/kord/common/entity/Snowflake;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; diff --git a/gateway/build.gradle.kts b/gateway/build.gradle.kts index 9f1d0b0569c7..c1479ace37bd 100644 --- a/gateway/build.gradle.kts +++ b/gateway/build.gradle.kts @@ -12,9 +12,19 @@ kotlin { api(libs.bundles.ktor.client.serialization) api(libs.ktor.client.websockets) + implementation(libs.kotlin.logging) + + // TODO remove when gatewayOnLogger and mu.KLogger.error() are removed + implementation(libs.kotlin.logging.old) + compileOnly(projects.kspAnnotations) } } + jvmMain { + dependencies { + implementation(libs.slf4j.api) + } + } jsMain { dependencies { implementation(libs.kotlin.node) diff --git a/gateway/src/commonMain/kotlin/DefaultGateway.kt b/gateway/src/commonMain/kotlin/DefaultGateway.kt index acb186da26c7..635fd38b9057 100644 --- a/gateway/src/commonMain/kotlin/DefaultGateway.kt +++ b/gateway/src/commonMain/kotlin/DefaultGateway.kt @@ -7,6 +7,7 @@ import dev.kord.gateway.GatewayCloseCode.* import dev.kord.gateway.handler.* import dev.kord.gateway.ratelimit.IdentifyRateLimiter import dev.kord.gateway.retry.Retry +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.client.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* @@ -22,7 +23,6 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.serialization.json.Json -import mu.KotlinLogging import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext @@ -119,7 +119,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway { */ inflater = Inflater() } catch (exception: Exception) { - defaultGatewayLogger.error(exception) + defaultGatewayLogger.error(exception) { "" } if (exception.isTimeout()) { data.eventFlow.emit(Close.Timeout) } @@ -131,7 +131,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway { try { readSocket() } catch (exception: Exception) { - defaultGatewayLogger.error(exception) + defaultGatewayLogger.error(exception) { "" } } defaultGatewayLogger.trace { "gateway connection closing" } @@ -139,7 +139,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway { try { handleClose() } catch (exception: Exception) { - defaultGatewayLogger.error(exception) + defaultGatewayLogger.error(exception) { "" } } defaultGatewayLogger.trace { "handled gateway connection closed" } @@ -189,7 +189,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway { val event = jsonParser.decodeFromString(Event.DeserializationStrategy, json) ?: return data.eventFlow.emit(event) } catch (exception: Exception) { - defaultGatewayLogger.error(exception) + defaultGatewayLogger.error(exception) { "" } } } diff --git a/gateway/src/commonMain/kotlin/Event.kt b/gateway/src/commonMain/kotlin/Event.kt index 18021d8a9ea4..7fcbf145600a 100644 --- a/gateway/src/commonMain/kotlin/Event.kt +++ b/gateway/src/commonMain/kotlin/Event.kt @@ -4,6 +4,7 @@ import dev.kord.common.entity.* import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInSeconds +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.datetime.Instant import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer @@ -21,7 +22,6 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject -import mu.KotlinLogging import kotlin.jvm.JvmField import kotlinx.serialization.DeserializationStrategy as KDeserializationStrategy diff --git a/gateway/src/commonMain/kotlin/Gateway.kt b/gateway/src/commonMain/kotlin/Gateway.kt index d0441540280e..886c874bc223 100644 --- a/gateway/src/commonMain/kotlin/Gateway.kt +++ b/gateway/src/commonMain/kotlin/Gateway.kt @@ -4,11 +4,10 @@ import dev.kord.common.entity.Snowflake import dev.kord.common.entity.optional.Optional import dev.kord.gateway.builder.PresenceBuilder import dev.kord.gateway.builder.RequestGuildMembersBuilder +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* -import mu.KLogger -import mu.KotlinLogging import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext @@ -140,11 +139,18 @@ public suspend inline fun Gateway.start(token: String, config: GatewayConfigurat start(builder.build()) } +@Suppress("unused") +@Deprecated("Binary compatibility, remove after deprecation cycle.", level = DeprecationLevel.WARNING) +@PublishedApi +internal val gatewayOnLogger: mu.KLogger = mu.KotlinLogging.logger("Gateway.on") + /** - * Logger used to report throwables caught in [Gateway.on]. + * Logger used to report [Throwable]s caught in [Gateway.on]. */ +private val logger = KotlinLogging.logger("Gateway.on") + @PublishedApi -internal val gatewayOnLogger: KLogger = KotlinLogging.logger("Gateway.on") +internal fun logCaughtThrowable(throwable: Throwable): Unit = logger.catching(throwable) /** * Convenience method that will invoke the [consumer] on every event [T] created by [Gateway.events]. @@ -162,7 +168,7 @@ public inline fun Gateway.on( crossinline consumer: suspend T.() -> Unit ): Job { return this.events.buffer(Channel.UNLIMITED).filterIsInstance().onEach { - launch { it.runCatching { it.consumer() }.onFailure(gatewayOnLogger::error) } + launch { it.runCatching { it.consumer() }.onFailure(::logCaughtThrowable) } }.launchIn(scope) } diff --git a/gateway/src/commonMain/kotlin/Ticker.kt b/gateway/src/commonMain/kotlin/Ticker.kt index 99c35b6a3a07..9e819ea2986d 100644 --- a/gateway/src/commonMain/kotlin/Ticker.kt +++ b/gateway/src/commonMain/kotlin/Ticker.kt @@ -1,5 +1,6 @@ package dev.kord.gateway +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -7,7 +8,6 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import mu.KotlinLogging import kotlin.coroutines.CoroutineContext private val logger = KotlinLogging.logger { } @@ -33,7 +33,7 @@ public class Ticker(private val dispatcher: CoroutineDispatcher = Dispatchers.De try { block() } catch (exception: Exception) { - logger.error(exception) + logger.error(exception) { "" } } }.launchIn(this) } diff --git a/gateway/src/commonMain/kotlin/Utils.kt b/gateway/src/commonMain/kotlin/Utils.kt index fd897c41b80c..7240b425b3c6 100644 --- a/gateway/src/commonMain/kotlin/Utils.kt +++ b/gateway/src/commonMain/kotlin/Utils.kt @@ -2,5 +2,7 @@ package dev.kord.gateway import mu.KLogger +@Suppress("DeprecatedCallableAddReplaceWith") +@Deprecated("Binary compatibility, remove after deprecation cycle.", level = DeprecationLevel.WARNING) @PublishedApi internal fun KLogger.error(throwable: Throwable): Unit = error(throwable) { "" } diff --git a/gateway/src/commonMain/kotlin/handler/Handler.kt b/gateway/src/commonMain/kotlin/handler/Handler.kt index 70277bfd3c91..a82e2b908131 100644 --- a/gateway/src/commonMain/kotlin/handler/Handler.kt +++ b/gateway/src/commonMain/kotlin/handler/Handler.kt @@ -1,12 +1,12 @@ package dev.kord.gateway.handler import dev.kord.gateway.Event +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import mu.KotlinLogging import kotlin.coroutines.CoroutineContext private val logger = KotlinLogging.logger("[Handler]") diff --git a/gateway/src/commonMain/kotlin/ratelimit/IdentifyRateLimiter.kt b/gateway/src/commonMain/kotlin/ratelimit/IdentifyRateLimiter.kt index c83de0194713..d9228a1a47d5 100644 --- a/gateway/src/commonMain/kotlin/ratelimit/IdentifyRateLimiter.kt +++ b/gateway/src/commonMain/kotlin/ratelimit/IdentifyRateLimiter.kt @@ -1,6 +1,7 @@ package dev.kord.gateway.ratelimit import dev.kord.gateway.* +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.atomicfu.atomic import kotlinx.atomicfu.getAndUpdate import kotlinx.atomicfu.loop @@ -11,7 +12,6 @@ import kotlinx.coroutines.channels.onSuccess import kotlinx.coroutines.flow.* import kotlinx.coroutines.selects.onTimeout import kotlinx.coroutines.selects.select -import mu.KotlinLogging import kotlin.jvm.JvmField import kotlin.time.Duration.Companion.seconds diff --git a/gateway/src/commonMain/kotlin/retry/LinearRetry.kt b/gateway/src/commonMain/kotlin/retry/LinearRetry.kt index 96bb00ec2a5f..23ea7bb7e252 100644 --- a/gateway/src/commonMain/kotlin/retry/LinearRetry.kt +++ b/gateway/src/commonMain/kotlin/retry/LinearRetry.kt @@ -1,9 +1,9 @@ package dev.kord.gateway.retry +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.atomicfu.atomic import kotlinx.atomicfu.update import kotlinx.coroutines.delay -import mu.KotlinLogging import kotlin.time.Duration import kotlin.time.times diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e2fafa558ab3..17b77358e1c2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,23 +1,24 @@ [versions] # api dependencies -kotlin = "1.9.20" # https://github.com/JetBrains/kotlin -ktor = "2.3.6" # https://github.com/ktorio/ktor +kotlin = "1.9.21" # https://github.com/JetBrains/kotlin +ktor = "2.3.7" # https://github.com/ktorio/ktor kotlinx-coroutines = "1.7.3" # https://github.com/Kotlin/kotlinx.coroutines -kotlinx-serialization = "1.6.1" # https://github.com/Kotlin/kotlinx.serialization -kotlinx-datetime = "0.4.1" # https://github.com/Kotlin/kotlinx-datetime -kotlin-logging = "3.0.5" # https://github.com/oshai/kotlin-logging +kotlinx-serialization = "1.6.2" # https://github.com/Kotlin/kotlinx.serialization +kotlinx-datetime = "0.5.0" # https://github.com/Kotlin/kotlinx-datetime +kotlin-logging = "6.0.1" # https://github.com/oshai/kotlin-logging +kotlin-logging-old = "3.0.5" # TODO remove after dependency is removed in rest, gateway, voice and core kord-cache = "0.4.0" # https://github.com/kordlib/cache # implementation dependencies kotlin-node = "18.16.12-pre.619" # https://github.com/JetBrains/kotlin-wrappers bignum = "0.3.8" # https://github.com/ionspin/kotlin-multiplatform-bignum -stately = "2.0.5" # https://github.com/touchlab/Stately +stately = "2.0.6" # https://github.com/touchlab/Stately fastZlib = "2.0.1" # https://github.com/timotejroiko/fast-zlib # code generation -ksp = "1.9.20-1.0.14" # https://github.com/google/ksp -kotlinpoet = "1.15.1" # https://github.com/square/kotlinpoet +ksp = "1.9.21-1.0.16" # https://github.com/google/ksp +kotlinpoet = "1.15.3" # https://github.com/square/kotlinpoet # tests junit5 = "5.10.1" # https://github.com/junit-team/junit5 @@ -26,9 +27,9 @@ slf4j = "2.0.9" # https://www.slf4j.org # plugins dokka = "1.9.10" # https://github.com/Kotlin/dokka -kotlinx-atomicfu = "0.23.0" # https://github.com/Kotlin/kotlinx-atomicfu +kotlinx-atomicfu = "0.23.1" # https://github.com/Kotlin/kotlinx-atomicfu binary-compatibility-validator = "0.13.2" # https://github.com/Kotlin/binary-compatibility-validator -buildconfig = "4.2.0" # https://github.com/gmazzo/gradle-buildconfig-plugin +buildconfig = "5.1.0" # https://github.com/gmazzo/gradle-buildconfig-plugin [libraries] @@ -55,7 +56,9 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } # other -kotlin-logging = { module = "io.github.microutils:kotlin-logging", version.ref = "kotlin-logging" } +kotlin-logging = { module = "io.github.oshai:kotlin-logging", version.ref = "kotlin-logging" } +kotlin-logging-old = { module = "io.github.microutils:kotlin-logging", version.ref = "kotlin-logging-old" } +slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } kotlin-node = { module = "org.jetbrains.kotlin-wrappers:kotlin-node", version.ref = "kotlin-node" } # JDK replacements diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c49b7..d64cd4917707 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 46671acb6e14..db8c3baafe34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/rest/build.gradle.kts b/rest/build.gradle.kts index 21202494c784..1e96bd4847c6 100644 --- a/rest/build.gradle.kts +++ b/rest/build.gradle.kts @@ -10,6 +10,8 @@ kotlin { api(projects.common) api(libs.bundles.ktor.client.serialization) + + implementation(libs.kotlin.logging) } } commonTest { @@ -17,5 +19,10 @@ kotlin { implementation(libs.ktor.client.mock) } } + jvmMain { + dependencies { + implementation(libs.slf4j.api) + } + } } } diff --git a/rest/src/commonMain/kotlin/ratelimit/AbstractRateLimiter.kt b/rest/src/commonMain/kotlin/ratelimit/AbstractRateLimiter.kt index 806cdb4ba8b9..0fb318762332 100644 --- a/rest/src/commonMain/kotlin/ratelimit/AbstractRateLimiter.kt +++ b/rest/src/commonMain/kotlin/ratelimit/AbstractRateLimiter.kt @@ -5,13 +5,13 @@ import dev.kord.common.ratelimit.IntervalRateLimiter import dev.kord.rest.request.Request import dev.kord.rest.request.RequestIdentifier import dev.kord.rest.request.identifier +import io.github.oshai.kotlinlogging.KLogger import kotlinx.atomicfu.atomic import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.delay import kotlinx.coroutines.sync.Mutex import kotlinx.datetime.Clock import kotlinx.datetime.Instant -import mu.KLogger import kotlin.time.Duration.Companion.minutes public abstract class AbstractRateLimiter internal constructor(public val clock: Clock) : RequestRateLimiter { diff --git a/rest/src/commonMain/kotlin/ratelimit/ExclusionRequestRateLimiter.kt b/rest/src/commonMain/kotlin/ratelimit/ExclusionRequestRateLimiter.kt index d77895a3a8a9..2e725a1f0fb4 100644 --- a/rest/src/commonMain/kotlin/ratelimit/ExclusionRequestRateLimiter.kt +++ b/rest/src/commonMain/kotlin/ratelimit/ExclusionRequestRateLimiter.kt @@ -3,10 +3,10 @@ package dev.kord.rest.ratelimit import dev.kord.rest.request.Request import dev.kord.rest.request.RequestIdentifier import dev.kord.rest.request.identifier +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.sync.Mutex import kotlinx.datetime.Clock -import mu.KLogger -import mu.KotlinLogging private val requestLogger = KotlinLogging.logger {} diff --git a/rest/src/commonMain/kotlin/ratelimit/ParallelRequestRateLimiter.kt b/rest/src/commonMain/kotlin/ratelimit/ParallelRequestRateLimiter.kt index c9fb055c255b..96ae127925ca 100644 --- a/rest/src/commonMain/kotlin/ratelimit/ParallelRequestRateLimiter.kt +++ b/rest/src/commonMain/kotlin/ratelimit/ParallelRequestRateLimiter.kt @@ -4,8 +4,8 @@ import dev.kord.common.annotation.KordUnsafe import dev.kord.rest.request.Request import dev.kord.rest.request.RequestIdentifier import dev.kord.rest.request.identifier -import mu.KLogger -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.datetime.Clock private val parallelLogger = KotlinLogging.logger {} diff --git a/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt b/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt index 524bdc1e99fa..f40480c32c4d 100644 --- a/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt +++ b/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt @@ -4,6 +4,7 @@ import dev.kord.common.http.httpEngine import dev.kord.rest.json.response.DiscordErrorResponse import dev.kord.rest.ratelimit.* import dev.kord.rest.route.optional +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.request.forms.* @@ -13,7 +14,6 @@ import io.ktor.http.* import io.ktor.http.content.* import kotlinx.datetime.Clock import kotlinx.serialization.json.Json -import mu.KotlinLogging internal val jsonDefault = Json { encodeDefaults = false diff --git a/voice/api/voice.api b/voice/api/voice.api index 186b2bbf5d6d..ba7fad45ce44 100644 --- a/voice/api/voice.api +++ b/voice/api/voice.api @@ -1009,6 +1009,7 @@ public final class dev/kord/voice/gateway/VoiceGatewayConfiguration { public final class dev/kord/voice/gateway/VoiceGatewayKt { public static final fun getVoiceGatewayOnLogger ()Lmu/KLogger; + public static final fun logCaughtThrowable (Ljava/lang/Throwable;)V } public final class dev/kord/voice/io/ByteArrayCursorsKt { diff --git a/voice/build.gradle.kts b/voice/build.gradle.kts index da6b41f43831..fbf4f4eaaad3 100644 --- a/voice/build.gradle.kts +++ b/voice/build.gradle.kts @@ -9,6 +9,12 @@ dependencies { api(projects.common) api(projects.gateway) + implementation(libs.kotlin.logging) + implementation(libs.slf4j.api) + + // TODO remove when voiceGatewayOnLogger is removed + implementation(libs.kotlin.logging.old) + compileOnly(projects.kspAnnotations) api(libs.ktor.network) diff --git a/voice/src/main/kotlin/gateway/DefaultVoiceGateway.kt b/voice/src/main/kotlin/gateway/DefaultVoiceGateway.kt index 9469a04f78c7..8cf5b33844c8 100644 --- a/voice/src/main/kotlin/gateway/DefaultVoiceGateway.kt +++ b/voice/src/main/kotlin/gateway/DefaultVoiceGateway.kt @@ -5,10 +5,10 @@ import dev.kord.common.entity.Snowflake import dev.kord.gateway.retry.Retry import dev.kord.voice.gateway.handler.HandshakeHandler import dev.kord.voice.gateway.handler.HeartbeatHandler +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.client.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* -import io.ktor.util.logging.* import io.ktor.websocket.* import kotlinx.atomicfu.AtomicRef import kotlinx.atomicfu.atomic @@ -20,7 +20,6 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.serialization.json.Json -import mu.KotlinLogging import kotlin.time.Duration private val defaultVoiceGatewayLogger = KotlinLogging.logger { } @@ -88,7 +87,7 @@ public class DefaultVoiceGateway( } catch (exception: Exception) { if (exception is CancellationException) break - defaultVoiceGatewayLogger.error(exception) + defaultVoiceGatewayLogger.error(exception) { "" } if (exception is java.nio.channels.UnresolvedAddressException) { data.eventFlow.emit(Close.Timeout) } @@ -114,7 +113,7 @@ public class DefaultVoiceGateway( } catch (exception: CancellationException) { defaultVoiceGatewayLogger.trace(exception) { "" } } catch (exception: Exception) { - defaultVoiceGatewayLogger.error(exception) + defaultVoiceGatewayLogger.error(exception) { "" } } defaultVoiceGatewayLogger.trace { "handled voice gateway connection closed" } @@ -154,7 +153,7 @@ public class DefaultVoiceGateway( data.eventFlow.emit(event) } catch (exception: Exception) { - defaultVoiceGatewayLogger.error(exception) + defaultVoiceGatewayLogger.error(exception) { "" } } } diff --git a/voice/src/main/kotlin/gateway/VoiceEvent.kt b/voice/src/main/kotlin/gateway/VoiceEvent.kt index f40c93c16bb5..6d5fd49ee413 100644 --- a/voice/src/main/kotlin/gateway/VoiceEvent.kt +++ b/voice/src/main/kotlin/gateway/VoiceEvent.kt @@ -3,6 +3,7 @@ package dev.kord.voice.gateway import dev.kord.common.entity.Snowflake import dev.kord.voice.EncryptionMode import dev.kord.voice.SpeakingFlags +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -12,7 +13,6 @@ import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.json.JsonElement -import mu.KotlinLogging import kotlinx.serialization.DeserializationStrategy as KDeserializationStrategy private val jsonLogger = KotlinLogging.logger { } diff --git a/voice/src/main/kotlin/gateway/VoiceGateway.kt b/voice/src/main/kotlin/gateway/VoiceGateway.kt index d19b14a12df0..9745812ed005 100644 --- a/voice/src/main/kotlin/gateway/VoiceGateway.kt +++ b/voice/src/main/kotlin/gateway/VoiceGateway.kt @@ -1,12 +1,10 @@ package dev.kord.voice.gateway import dev.kord.common.annotation.KordVoice -import io.ktor.util.logging.* +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* -import mu.KLogger -import mu.KotlinLogging import kotlin.coroutines.EmptyCoroutineContext import kotlin.time.Duration @@ -88,11 +86,18 @@ public interface VoiceGateway { } +@Suppress("unused") +@Deprecated("Binary compatibility, remove after deprecation cycle.", level = DeprecationLevel.WARNING) +@PublishedApi +internal val voiceGatewayOnLogger: mu.KLogger = mu.KotlinLogging.logger("Gateway.on") + /** - * Logger used to report throwables caught in [VoiceGateway.on]. + * Logger used to report [Throwable]s caught in [VoiceGateway.on]. */ +private val logger = KotlinLogging.logger("Gateway.on") + @PublishedApi -internal val voiceGatewayOnLogger: KLogger = KotlinLogging.logger("Gateway.on") +internal fun logCaughtThrowable(throwable: Throwable): Unit = logger.catching(throwable) /** * Convenience method that will invoke the [consumer] on every event [T] created by [VoiceGateway.events]. @@ -111,7 +116,7 @@ public inline fun VoiceGateway.on( crossinline consumer: suspend T.() -> Unit ): Job { return this.events.buffer(Channel.UNLIMITED).filterIsInstance().onEach { - scope.launch { it.runCatching { it.consumer() }.onFailure(voiceGatewayOnLogger::error) } + scope.launch { it.runCatching { it.consumer() }.onFailure(::logCaughtThrowable) } }.launchIn(scope) } diff --git a/voice/src/main/kotlin/gateway/handler/GatewayEventHandler.kt b/voice/src/main/kotlin/gateway/handler/GatewayEventHandler.kt index 9194f8c0ba04..6eb21a7b3340 100644 --- a/voice/src/main/kotlin/gateway/handler/GatewayEventHandler.kt +++ b/voice/src/main/kotlin/gateway/handler/GatewayEventHandler.kt @@ -1,12 +1,12 @@ package dev.kord.voice.gateway.handler import dev.kord.voice.gateway.VoiceEvent +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import mu.KotlinLogging private val logger = KotlinLogging.logger("[Handler]") @@ -25,4 +25,4 @@ internal abstract class GatewayEventHandler( } }.launchIn(this) } -} \ No newline at end of file +} diff --git a/voice/src/main/kotlin/handlers/ConnectionEventHandler.kt b/voice/src/main/kotlin/handlers/ConnectionEventHandler.kt index 0733d7f167c6..de49ebe3b820 100644 --- a/voice/src/main/kotlin/handlers/ConnectionEventHandler.kt +++ b/voice/src/main/kotlin/handlers/ConnectionEventHandler.kt @@ -1,11 +1,11 @@ package dev.kord.voice.handlers +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import mu.KotlinLogging private val logger = KotlinLogging.logger("[Interceptor]") @@ -24,4 +24,4 @@ internal abstract class ConnectionEventHandler( } }.launchIn(this) } -} \ No newline at end of file +} diff --git a/voice/src/main/kotlin/handlers/UdpLifeCycleHandler.kt b/voice/src/main/kotlin/handlers/UdpLifeCycleHandler.kt index f0c33017a617..7d9004417a65 100644 --- a/voice/src/main/kotlin/handlers/UdpLifeCycleHandler.kt +++ b/voice/src/main/kotlin/handlers/UdpLifeCycleHandler.kt @@ -8,13 +8,13 @@ import dev.kord.voice.encryption.strategies.NormalNonceStrategy import dev.kord.voice.encryption.strategies.SuffixNonceStrategy import dev.kord.voice.gateway.* import dev.kord.voice.udp.AudioFrameSenderConfiguration +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.network.sockets.* import kotlinx.atomicfu.atomic import kotlinx.coroutines.Job import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch -import mu.KotlinLogging private val udpLifeCycleLogger = KotlinLogging.logger { } diff --git a/voice/src/main/kotlin/handlers/VoiceUpdateEventHandler.kt b/voice/src/main/kotlin/handlers/VoiceUpdateEventHandler.kt index 96ed8af57439..a07c47354f4c 100644 --- a/voice/src/main/kotlin/handlers/VoiceUpdateEventHandler.kt +++ b/voice/src/main/kotlin/handlers/VoiceUpdateEventHandler.kt @@ -5,13 +5,13 @@ import dev.kord.common.annotation.KordVoice import dev.kord.gateway.VoiceServerUpdate import dev.kord.gateway.VoiceStateUpdate import dev.kord.voice.VoiceConnection +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.atomicfu.atomic import kotlinx.coroutines.Job import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch -import mu.KotlinLogging import kotlin.time.Duration import dev.kord.gateway.Event as GatewayEvent diff --git a/voice/src/main/kotlin/streams/DefaultStreams.kt b/voice/src/main/kotlin/streams/DefaultStreams.kt index 8a44186c3500..0907f1ff895c 100644 --- a/voice/src/main/kotlin/streams/DefaultStreams.kt +++ b/voice/src/main/kotlin/streams/DefaultStreams.kt @@ -12,6 +12,7 @@ import dev.kord.voice.io.* import dev.kord.voice.udp.PayloadType import dev.kord.voice.udp.RTPPacket import dev.kord.voice.udp.VoiceUdpSocket +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.network.sockets.* import kotlinx.atomicfu.AtomicRef import kotlinx.atomicfu.atomic @@ -20,7 +21,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.* -import mu.KotlinLogging private val defaultStreamsLogger = KotlinLogging.logger { } diff --git a/voice/src/main/kotlin/udp/DefaultAudioFrameSender.kt b/voice/src/main/kotlin/udp/DefaultAudioFrameSender.kt index d713cff99fb4..3edeb832c775 100644 --- a/voice/src/main/kotlin/udp/DefaultAudioFrameSender.kt +++ b/voice/src/main/kotlin/udp/DefaultAudioFrameSender.kt @@ -5,13 +5,13 @@ import dev.kord.voice.AudioFrame import dev.kord.voice.AudioProvider import dev.kord.voice.FrameInterceptor import dev.kord.voice.encryption.strategies.NonceStrategy +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.network.sockets.* import io.ktor.utils.io.core.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch -import mu.KotlinLogging import kotlin.random.Random private val audioFrameSenderLogger = KotlinLogging.logger { } @@ -54,4 +54,4 @@ public class DefaultAudioFrameSender( /* we're done polling, nothing to worry about */ } } -} \ No newline at end of file +} diff --git a/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt b/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt index 407525dd7912..d4577e45cf32 100644 --- a/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt +++ b/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt @@ -1,6 +1,7 @@ package dev.kord.voice.udp import dev.kord.common.annotation.KordVoice +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.network.selector.* import io.ktor.network.sockets.* import io.ktor.utils.io.core.* @@ -9,7 +10,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.flow.* -import mu.KotlinLogging import kotlin.text.String private val globalVoiceSocketLogger = KotlinLogging.logger { }