2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.domain.logging
22 import org.onap.dcae.collectors.veshv.utils.logging.Logger
23 import org.onap.dcae.collectors.veshv.utils.logging.MappedDiagnosticContext
27 @Suppress("TooManyFunctions")
28 object MarkerLogging {
29 fun Logger.error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
30 withError(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
32 fun Logger.error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) =
33 withError(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message(), t) } }
35 fun Logger.warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
36 withWarn(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
38 fun Logger.warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) =
39 withWarn(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message(), t) } }
41 fun Logger.info(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
42 withInfo(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
44 fun Logger.debug(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
45 withDebug(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
47 fun Logger.trace(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
48 withTrace(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
51 private inline fun withAdditionalMdc(mdc: Map<String, String>, block: () -> Unit) {
59 mdc.keys.forEach(MDC::remove)