Skip to content

Commit

Permalink
feat(oppijanumero): change runCatching to try-catch
Browse files Browse the repository at this point in the history
and add key-values to logging indicate whether the parsing was succeed
  • Loading branch information
saku-koodari committed Dec 30, 2024
1 parent 1694a90 commit 9c78a5d
Show file tree
Hide file tree
Showing 5 changed files with 452 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
import fi.oph.kitu.logging.addCondition
import fi.oph.kitu.logging.withEvent
import fi.oph.kitu.logging.withTryCatch
import org.slf4j.LoggerFactory
import org.slf4j.Logger
import org.slf4j.spi.LoggingEventBuilder
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.net.URI
Expand All @@ -20,9 +21,9 @@ interface OppijanumeroService {
class OppijanumeroServiceImpl(
private val casAuthenticatedService: CasAuthenticatedService,
val objectMapper: ObjectMapper,
@Qualifier("oppijanumeroServiceLogger")
private val logger: Logger,
) : OppijanumeroService {
private val logger = LoggerFactory.getLogger(javaClass)

@Value("\${kitu.oppijanumero.service.url}")
lateinit var serviceUrl: String

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fi.oph.kitu.oppijanumero

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class OppijanumeroServiceLoggerConfig {
@Bean("oppijanumeroServiceLogger")
fun logger(): Logger = LoggerFactory.getLogger(OppijanumeroService::class.java)
}
8 changes: 8 additions & 0 deletions server/src/test/kotlin/fi/oph/kitu/logging/MockEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class MockEvent : LoggingEventBuilder {
val logs = mutableListOf<String?>()
val defaultLogValue: String = "NULL"

/** Gets value from keyValues - list by the given key. */
inline fun <reified T> getValueOrNullByKey(key: String) =
keyValues
.filter { it.first == key }
.map { it.second }
.filterIsInstance<T>()
.firstOrNull()

override fun setCause(p0: Throwable?): LoggingEventBuilder {
causes.add(p0)
return this
Expand Down
Loading

0 comments on commit 9c78a5d

Please sign in to comment.