Skip to content

Commit 370d869

Browse files
author
m.zharinova
committed
exclude detect-formatting as it causes initialization error in tests
1 parent 1f59029 commit 370d869

File tree

7 files changed

+40
-38
lines changed

7 files changed

+40
-38
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kotlin version: 2.0.21
2+
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
3+
1. Kotlin compile daemon is ready
4+

buildSrc/src/main/kotlin/sb-ot-demo.kotlin-conventions.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020

2121
dependencies {
2222
implementation("org.jetbrains.kotlin:kotlin-reflect")
23-
implementation("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.6")
23+
//implementation("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.6")
2424
implementation("io.gitlab.arturbosch.detekt:detekt-rules-libraries:1.23.6")
2525
}
2626

@@ -47,8 +47,6 @@ tasks {
4747
testLogging.showStandardStreams = false // set to true for debug purposes
4848
}
4949
}
50-
configurations.all {
51-
exclude(group = "ch.qos.logback")
52-
}
50+
5351

5452

spring-boot-3-demo-app-kotlin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
implementation("com.github.blagerweij:liquibase-sessionlock")
3333
implementation("net.ttddyy.observation:datasource-micrometer-spring-boot:1.1.0")
3434
implementation("net.logstash.logback:logstash-logback-encoder:8.0")
35+
implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
3536

3637
testImplementation("org.springframework.boot:spring-boot-starter-test")
3738
testImplementation("org.springframework.boot:spring-boot-starter-webflux")

spring-boot-3-demo-app-kotlin/src/main/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/TimeController.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ package io.github.mfvanek.spring.boot3.kotlin.test
88

99
import io.github.mfvanek.spring.boot3.kotlin.test.service.KafkaSendingService
1010
import io.github.mfvanek.spring.boot3.kotlin.test.service.PublicApiService
11+
import io.github.oshai.kotlinlogging.KotlinLogging
1112
import io.micrometer.tracing.Tracer
12-
import mu.KotlinLogging
13-
import org.springframework.web.bind.annotation.GetMapping
14-
import org.springframework.web.bind.annotation.RestController
1513
import java.time.Clock
1614
import java.time.LocalDateTime
15+
import org.springframework.web.bind.annotation.GetMapping
16+
import org.springframework.web.bind.annotation.RestController
1717

1818
private val logger = KotlinLogging.logger {}
1919

2020
@RestController
21-
class TimeController (
21+
class TimeController(
2222
private val tracer: Tracer,
2323
private val clock: Clock,
2424
private val kafkaSendingService: KafkaSendingService,
2525
private val publicApiService: PublicApiService
26-
) {
26+
) {
2727

2828
@GetMapping(path = ["/current-time"])
2929
fun getNow(): LocalDateTime {
30-
logger.trace("tracer {}", tracer)
30+
logger.trace { "tracer $tracer" }
3131
val traceId = tracer.currentSpan()?.context()?.traceId()
32-
logger.info("Called method getNow. TraceId = {}", traceId)
32+
logger.info { "Called method getNow. TraceId = $traceId" }
3333
val nowFromRemote = publicApiService.getZonedTime()
3434
val now = nowFromRemote ?: LocalDateTime.now(clock)
3535
kafkaSendingService.sendNotification("Current time = $now")

spring-boot-3-demo-app-kotlin/src/main/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/service/KafkaReadingService.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package io.github.mfvanek.spring.boot3.kotlin.test.service
22

3+
import io.github.oshai.kotlinlogging.KotlinLogging
4+
import io.github.oshai.kotlinlogging.withLoggingContext
35
import io.micrometer.tracing.Tracer
4-
import mu.KotlinLogging
6+
import java.time.Clock
7+
import java.time.LocalDateTime
8+
import java.util.UUID
59
import org.apache.kafka.clients.consumer.ConsumerRecord
6-
import org.slf4j.MDC
710
import org.springframework.beans.factory.annotation.Value
811
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
912
import org.springframework.kafka.annotation.KafkaListener
1013
import org.springframework.kafka.support.Acknowledgment
1114
import org.springframework.stereotype.Service
12-
import java.time.Clock
13-
import java.time.LocalDateTime
14-
import java.util.UUID
1515

1616
private val logger = KotlinLogging.logger {}
1717

@@ -23,11 +23,11 @@ class KafkaReadingService(
2323
private val jdbcTemplate: NamedParameterJdbcTemplate
2424
) {
2525
@KafkaListener(topics = ["\${spring.kafka.template.default-topic}"])
26-
fun listen(message: ConsumerRecord<UUID, String>, ack: Acknowledgment){
27-
MDC.putCloseable("tenant.name", tenantName).use {
26+
fun listen(message: ConsumerRecord<UUID, String>, ack: Acknowledgment) {
27+
withLoggingContext("tenant.name" to tenantName) {
2828
val currentSpan = tracer.currentSpan()
2929
val traceId = currentSpan?.context()?.traceId() ?: ""
30-
logger.info("Received record: {} with traceId {}", message.value(), traceId)
30+
logger.info{"Received record: ${message.value()} with traceId $traceId"}
3131
jdbcTemplate.update(
3232
"insert into otel_demo.storage(message, trace_id, created_at) values(:msg, :traceId, :createdAt);",
3333
mapOf(

spring-boot-3-demo-app-kotlin/src/main/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/service/KafkaSendingService.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.github.mfvanek.spring.boot3.kotlin.test.service
22

3-
import mu.KotlinLogging
4-
import org.slf4j.MDC
3+
import io.github.oshai.kotlinlogging.KotlinLogging
4+
import io.github.oshai.kotlinlogging.withLoggingContext
5+
import java.util.UUID
6+
import java.util.concurrent.CompletableFuture
57
import org.springframework.beans.factory.annotation.Value
68
import org.springframework.kafka.core.KafkaTemplate
79
import org.springframework.kafka.support.SendResult
810
import org.springframework.stereotype.Service
9-
import java.util.UUID
10-
import java.util.concurrent.CompletableFuture
1111

1212
private val logger = KotlinLogging.logger {}
1313

@@ -17,8 +17,8 @@ class KafkaSendingService(
1717
private val kafkaTemplate: KafkaTemplate<UUID, String>
1818
) {
1919
fun sendNotification(message: String): CompletableFuture<SendResult<UUID, String>> {
20-
MDC.putCloseable("tenant.name", tenantName).use {
21-
logger.info("Sending message \"{}\" to Kafka", message)
20+
withLoggingContext("tenant.name" to tenantName) {
21+
logger.info{"Sending message \"$message\" to Kafka"}
2222
return kafkaTemplate.sendDefault(UUID.randomUUID(), message)
2323
}
2424
}

spring-boot-3-demo-app-kotlin/src/main/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/service/PublicApiService.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import com.fasterxml.jackson.databind.ObjectMapper
1111
import io.github.mfvanek.spring.boot3.kotlin.test.service.dto.CurrentTime
1212
import io.github.mfvanek.spring.boot3.kotlin.test.service.dto.ParsedDateTime
1313
import io.github.mfvanek.spring.boot3.kotlin.test.service.dto.toLocalDateTime
14-
import mu.KotlinLogging
15-
import org.slf4j.MDC
14+
import java.time.Duration
15+
import java.time.LocalDateTime
16+
import java.util.TimeZone
17+
import io.github.oshai.kotlinlogging.KotlinLogging
18+
import io.github.oshai.kotlinlogging.withLoggingContext
1619
import org.springframework.beans.factory.annotation.Value
1720
import org.springframework.http.MediaType
1821
import org.springframework.retry.ExhaustedRetryException
1922
import org.springframework.stereotype.Service
2023
import org.springframework.web.reactive.function.client.WebClient
2124
import reactor.util.retry.Retry
22-
import java.time.Duration
23-
import java.time.LocalDateTime
24-
import java.util.TimeZone
2525

2626
private val logger = KotlinLogging.logger {}
2727

@@ -36,9 +36,9 @@ class PublicApiService(
3636
val result: ParsedDateTime = getZonedTimeFromWorldTimeApi().datetime
3737
return result.toLocalDateTime()
3838
} catch (e: ExhaustedRetryException) {
39-
logger.warn("Failed to get response", e)
39+
logger.warn { "Failed to get response $e" }
4040
} catch (e: JsonProcessingException) {
41-
logger.warn("Failed to convert response", e)
41+
logger.warn { "Failed to convert response $e" }
4242
}
4343
return null
4444
}
@@ -57,15 +57,14 @@ class PublicApiService(
5757
private fun prepareRetry(zoneName: String): Retry {
5858
return Retry.fixedDelay(retries.toLong(), Duration.ofSeconds(2))
5959
.doBeforeRetry { retrySignal: Retry.RetrySignal ->
60-
MDC.putCloseable("instance_timezone", zoneName).use {
61-
logger.info(
62-
"Retrying request to '/{}', attempt {}/{} due to error:",
63-
zoneName, retrySignal.totalRetries() + 1, retries, retrySignal.failure()
64-
)
60+
withLoggingContext("instance_timezone" to zoneName) {
61+
logger.info {
62+
"Retrying request to '/$zoneName', attempt ${retrySignal.totalRetries() + 1}/${retrySignal.failure()} due to error:"
63+
}
6564
}
6665
}
6766
.onRetryExhaustedThrow { _, retrySignal: Retry.RetrySignal ->
68-
logger.error("Request to '/{}' failed after {} attempts.", zoneName, retrySignal.totalRetries() + 1)
67+
logger.error { "Request to '/$zoneName' failed after ${retrySignal.totalRetries() + 1} attempts." }
6968
ExhaustedRetryException("Retries exhausted", retrySignal.failure())
7069
}
7170
}

0 commit comments

Comments
 (0)