diff --git a/src/main/kotlin/ltd/hlaeja/service/DeviceConfigurationService.kt b/src/main/kotlin/ltd/hlaeja/service/DeviceConfigurationService.kt index 765d8c7..4eb8c8f 100644 --- a/src/main/kotlin/ltd/hlaeja/service/DeviceConfigurationService.kt +++ b/src/main/kotlin/ltd/hlaeja/service/DeviceConfigurationService.kt @@ -3,7 +3,7 @@ package ltd.hlaeja.service import java.util.UUID import ltd.hlaeja.library.deviceConfiguration.Node import ltd.hlaeja.property.DeviceConfigurationProperty -import mu.KotlinLogging +import ltd.hlaeja.util.logCall import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.NO_CONTENT import org.springframework.http.HttpStatus.REQUEST_TIMEOUT @@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.server.ResponseStatusException -private val log = KotlinLogging.logger {} - @Service class DeviceConfigurationService( private val webClient: WebClient, @@ -27,8 +25,4 @@ class DeviceConfigurationService( .retrieve() .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) } .awaitBodyOrNull() ?: throw ResponseStatusException(REQUEST_TIMEOUT) - - private fun logCall(url: String) { - log.debug("calling: {}", url) - } } diff --git a/src/main/kotlin/ltd/hlaeja/service/DeviceDataService.kt b/src/main/kotlin/ltd/hlaeja/service/DeviceDataService.kt index 124ef9a..9f790e1 100644 --- a/src/main/kotlin/ltd/hlaeja/service/DeviceDataService.kt +++ b/src/main/kotlin/ltd/hlaeja/service/DeviceDataService.kt @@ -3,7 +3,7 @@ package ltd.hlaeja.service import java.util.UUID import ltd.hlaeja.library.deviceData.MeasurementData import ltd.hlaeja.property.DeviceDataProperty -import mu.KotlinLogging +import ltd.hlaeja.util.logCall import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.NO_CONTENT import org.springframework.http.HttpStatus.REQUEST_TIMEOUT @@ -13,8 +13,6 @@ import org.springframework.web.reactive.function.client.awaitBodilessEntity import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.server.ResponseStatusException -private val log = KotlinLogging.logger {} - @Service class DeviceDataService( private val webClient: WebClient, @@ -25,8 +23,7 @@ class DeviceDataService( client: UUID, node: UUID, ): MeasurementData.Response = webClient.get() - .uri("${deviceDataProperty.url}/client-$client/node-$node") - .also { log.debug("{}/client-{}/node-{}", deviceDataProperty.url, client, node) } + .uri("${deviceDataProperty.url}/client-$client/node-$node".also(::logCall)) .retrieve() .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) } .awaitBodyOrNull() ?: throw ResponseStatusException(REQUEST_TIMEOUT) @@ -35,8 +32,7 @@ class DeviceDataService( client: UUID, request: MeasurementData.Request, ) = webClient.post() - .uri("${deviceDataProperty.url}/client-$client") - .also { log.debug("{}/client-{}", deviceDataProperty.url, client) } + .uri("${deviceDataProperty.url}/client-$client".also(::logCall)) .bodyValue(request) .retrieve() .awaitBodilessEntity() diff --git a/src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt b/src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt index dbe5957..397e1a0 100644 --- a/src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt +++ b/src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt @@ -3,7 +3,7 @@ package ltd.hlaeja.service import java.util.UUID import ltd.hlaeja.library.deviceRegistry.Identity import ltd.hlaeja.property.DeviceRegistryProperty -import mu.KotlinLogging +import ltd.hlaeja.util.logCall import org.springframework.http.HttpStatus.NOT_ACCEPTABLE import org.springframework.http.HttpStatus.NOT_FOUND import org.springframework.http.HttpStatus.REQUEST_TIMEOUT @@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.awaitBodyOrNull import org.springframework.web.server.ResponseStatusException -private val log = KotlinLogging.logger {} - @Service class DeviceRegistryService( private val webClient: WebClient, @@ -23,8 +21,7 @@ class DeviceRegistryService( suspend fun getIdentityFromDevice( device: UUID, ): Identity.Response = webClient.get() - .uri("${deviceRegistryProperty.url}/identity/device-$device") - .also { log.debug("{}/node/device-{}", deviceRegistryProperty.url, device) } + .uri("${deviceRegistryProperty.url}/identity/device-$device".also(::logCall)) .retrieve() .onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_ACCEPTABLE) } .awaitBodyOrNull() ?: throw ResponseStatusException(REQUEST_TIMEOUT) diff --git a/src/main/kotlin/ltd/hlaeja/util/Helper.kt b/src/main/kotlin/ltd/hlaeja/util/Helper.kt new file mode 100644 index 0000000..f77be8e --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/util/Helper.kt @@ -0,0 +1,9 @@ +package ltd.hlaeja.util + +import mu.KotlinLogging + +private val log = KotlinLogging.logger {} + +fun logCall(url: String) { + log.debug("calling: {}", url) +}