diff options
Diffstat (limited to 'sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt')
-rw-r--r-- | sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt | 16 |
1 files changed, 16 insertions, 0 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}" } +} |