summaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-utils/src/main/kotlin/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'sources/hv-collector-utils/src/main/kotlin/org/onap')
-rw-r--r--sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt16
-rw-r--r--sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt19
2 files changed, 19 insertions, 16 deletions
diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt
index 99ecfd74..7d92ddaf 100644
--- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt
+++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt
@@ -72,3 +72,19 @@ fun <T> Flux<T>.filterFailedWithLog(logger: Logger,
Mono.just<T>(t)
})
}
+
+
+fun <T> Mono<T>.onErrorLog(logger: Logger,
+ mdc: () -> Map<String, String>,
+ msg: () -> String) =
+ doOnError { logException(logger, mdc, msg, it) }
+
+fun <T> Flux<T>.onErrorLog(logger: Logger,
+ mdc: () -> Map<String, String>,
+ msg: () -> String) =
+ doOnError { logException(logger, mdc, msg, it) }
+
+private fun logException(logger: Logger, mdc: () -> Map<String, String>, msg: () -> String, it: Throwable) {
+ logger.error(mdc) { "${msg()}: ${it.message}" }
+ logger.debug(mdc) { "Detailed stack trace: ${it}" }
+}
diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt
index 2678a8d5..87aea41e 100644
--- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt
+++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt
@@ -19,23 +19,10 @@
*/
package org.onap.dcae.collectors.veshv.utils
-import arrow.effects.IO
-
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since January 2019
*/
-
-fun registerShutdownHook(job: () -> Unit) {
- Runtime.getRuntime().addShutdownHook(object : Thread() {
- override fun run() {
- job()
- }
- })
-}
-
-fun registerShutdownHook(job: IO<Unit>) = IO {
- registerShutdownHook {
- job.unsafeRunSync()
- }
-}
+fun registerShutdownHook(job: () -> Unit) =
+ Runtime.getRuntime()
+ .addShutdownHook(Thread({ job() }, "GracefulShutdownThread"))