diff options
author | kjaniak <kornel.janiak@nokia.com> | 2019-04-03 15:48:28 +0200 |
---|---|---|
committer | Filip Krzywka <filip.krzywka@nokia.com> | 2019-04-12 09:56:50 +0200 |
commit | 49f43c856c8ca793bc6972d9d4b47c2d0d4c0816 (patch) | |
tree | 1e2c7d124898e053d5a3d42f9dcb329d24050d0e /sources/hv-collector-utils/src/main | |
parent | 8b8385d323754903ade492a659548d54b56bd7ad (diff) |
Creation of server module
Issue-ID: DCAEGEN2-1390
Change-Id: I07410b16ed6566b933d5f1efa35bddb965225794
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-utils/src/main')
3 files changed, 21 insertions, 155 deletions
diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt index 7fcc73a0..14bc3ec0 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt @@ -23,6 +23,7 @@ import ch.qos.logback.classic.LoggerContext import kotlin.reflect.KClass import org.slf4j.LoggerFactory import org.slf4j.MDC +import org.slf4j.Marker typealias MappedDiagnosticContext = () -> Map<String, String> @@ -52,91 +53,70 @@ class Logger(logger: org.slf4j.Logger) { fun withError(block: AtLevelLogger.() -> Unit) = errorLogger.block() fun withError(mdc: MappedDiagnosticContext, block: AtLevelLogger.() -> Unit) = - errorLogger.withMdc(mdc, block) + errorLogger.withMdc(mdc, block) fun error(message: () -> String) = errorLogger.run { log(message()) } fun error(mdc: MappedDiagnosticContext, message: () -> String) = - errorLogger.withMdc(mdc) { log(message()) } - - fun error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) = - errorLogger.withMdc(mdc) { log(marker, message()) } - - fun error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) = - errorLogger.withMdc(mdc) { log(marker, message(), t) } + errorLogger.withMdc(mdc) { log(message()) } // WARN fun withWarn(block: AtLevelLogger.() -> Unit) = warnLogger.block() fun withWarn(mdc: MappedDiagnosticContext, block: AtLevelLogger.() -> Unit) = - warnLogger.withMdc(mdc, block) + warnLogger.withMdc(mdc, block) fun warn(message: () -> String) = warnLogger.run { log(message()) } fun warn(mdc: MappedDiagnosticContext, message: () -> String) = - warnLogger.withMdc(mdc) { log(message()) } - - fun warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) = - warnLogger.withMdc(mdc) { log(marker, message()) } - - fun warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) = - warnLogger.withMdc(mdc) { log(marker, message(), t) } + warnLogger.withMdc(mdc) { log(message()) } // INFO fun withInfo(block: AtLevelLogger.() -> Unit) = infoLogger.block() fun withInfo(mdc: MappedDiagnosticContext, block: AtLevelLogger.() -> Unit) = - infoLogger.withMdc(mdc, block) + infoLogger.withMdc(mdc, block) fun info(message: () -> String) = infoLogger.run { log(message()) } fun info(mdc: MappedDiagnosticContext, message: () -> String) = - infoLogger.withMdc(mdc) { log(message()) } - - fun info(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) = - infoLogger.withMdc(mdc) { log(marker, message()) } + infoLogger.withMdc(mdc) { log(message()) } // DEBUG fun withDebug(block: AtLevelLogger.() -> Unit) = debugLogger.block() fun withDebug(mdc: MappedDiagnosticContext, block: AtLevelLogger.() -> Unit) = - debugLogger.withMdc(mdc, block) + debugLogger.withMdc(mdc, block) fun debug(message: () -> String) = debugLogger.run { log(message()) } fun debug(mdc: MappedDiagnosticContext, message: () -> String) = - debugLogger.withMdc(mdc) { log(message()) } - - fun debug(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) = - debugLogger.withMdc(mdc) { log(marker, message()) } + debugLogger.withMdc(mdc) { log(message()) } // TRACE fun withTrace(block: AtLevelLogger.() -> Unit) = traceLogger.block() fun withTrace(mdc: MappedDiagnosticContext, block: AtLevelLogger.() -> Unit) = - traceLogger.withMdc(mdc, block) + traceLogger.withMdc(mdc, block) fun trace(message: () -> String) = traceLogger.run { log(message()) } fun trace(mdc: MappedDiagnosticContext, message: () -> String) = - traceLogger.withMdc(mdc) { log(message()) } - - fun trace(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) = - traceLogger.withMdc(mdc) { log(marker, message()) } + traceLogger.withMdc(mdc) { log(message()) } companion object { fun setLogLevel(packageName: String, level: LogLevel) { @@ -165,19 +145,6 @@ abstract class AtLevelLogger { } } } - - protected fun withAdditionalMdc(mdc: Map<String, String>, block: () -> Unit) { - if (mdc.isEmpty()) { - block() - } else { - try { - mdc.forEach(MDC::put) - block() - } finally { - mdc.keys.forEach(MDC::remove) - } - } - } } object OffLevelLogger : AtLevelLogger() { @@ -211,14 +178,10 @@ class ErrorLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() { } override fun log(marker: Marker, message: String) = - withAdditionalMdc(marker.mdc) { - logger.error(marker.slf4jMarker, message) - } + logger.error(marker, message) override fun log(marker: Marker, message: String, t: Throwable) = - withAdditionalMdc(marker.mdc) { - logger.error(marker.slf4jMarker, message, t) - } + logger.error(marker, message, t) } @Suppress("SuboptimalLoggerUsage") @@ -232,14 +195,10 @@ class WarnLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() { } override fun log(marker: Marker, message: String) = - withAdditionalMdc(marker.mdc) { - logger.warn(marker.slf4jMarker, message) - } + logger.warn(marker, message) override fun log(marker: Marker, message: String, t: Throwable) = - withAdditionalMdc(marker.mdc) { - logger.warn(marker.slf4jMarker, message, t) - } + logger.warn(marker, message, t) } @Suppress("SuboptimalLoggerUsage") @@ -253,14 +212,10 @@ class InfoLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() { } override fun log(marker: Marker, message: String) = - withAdditionalMdc(marker.mdc) { - logger.info(marker.slf4jMarker, message) - } + logger.info(marker, message) override fun log(marker: Marker, message: String, t: Throwable) = - withAdditionalMdc(marker.mdc) { - logger.info(marker.slf4jMarker, message, t) - } + logger.info(marker, message, t) } @Suppress("SuboptimalLoggerUsage") @@ -274,14 +229,10 @@ class DebugLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() { } override fun log(marker: Marker, message: String) = - withAdditionalMdc(marker.mdc) { - logger.debug(marker.slf4jMarker, message) - } + logger.debug(marker, message) override fun log(marker: Marker, message: String, t: Throwable) = - withAdditionalMdc(marker.mdc) { - logger.debug(marker.slf4jMarker, message, t) - } + logger.debug(marker, message, t) } @Suppress("SuboptimalLoggerUsage") @@ -295,12 +246,8 @@ class TraceLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() { } override fun log(marker: Marker, message: String) = - withAdditionalMdc(marker.mdc) { - logger.trace(marker.slf4jMarker, message) - } + logger.trace(marker, message) override fun log(marker: Marker, message: String, t: Throwable) = - withAdditionalMdc(marker.mdc) { - logger.trace(marker.slf4jMarker, message, t) - } + logger.trace(marker, message, t) } diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt deleted file mode 100644 index ac39100d..00000000 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.logging - -import org.slf4j.MarkerFactory -import java.time.Instant -import java.util.* - -sealed class Marker(internal val slf4jMarker: org.slf4j.Marker, val mdc: Map<String, String> = emptyMap()) { - - object Entry : Marker(ENTRY) - object Exit : Marker(EXIT) - - class Invoke(id: UUID = UUID.randomUUID(), timestamp: Instant = Instant.now()) : - Marker(INVOKE, mdc(id, timestamp)) { - companion object { - private fun mdc(id: UUID, timestamp: Instant) = mapOf( - OnapMdc.INVOCATION_ID to id.toString(), - OnapMdc.INVOCATION_TIMESTAMP to timestamp.toString() - ) - } - } - - companion object { - private val ENTRY = MarkerFactory.getMarker("ENTRY") - private val EXIT = MarkerFactory.getMarker("EXIT") - private val INVOKE = MarkerFactory.getMarker("INVOKE") - } -} diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/OnapMdc.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/OnapMdc.kt deleted file mode 100644 index 86584164..00000000 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/OnapMdc.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.logging - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since December 2018 - */ -object OnapMdc { - const val REQUEST_ID = "RequestID" - const val CLIENT_NAME = "PartnerName" - const val CLIENT_IP = "ClientIPAddress" - const val INVOCATION_ID = "InvocationID" - const val INVOCATION_TIMESTAMP = "InvokeTimestamp" - const val STATUS_CODE = "StatusCode" - const val INSTANCE_ID = "InstanceID" - const val SERVER_FQDN = "ServerFQDN" -} |