aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-utils/src/main
diff options
context:
space:
mode:
authorFilip Krzywka <filip.krzywka@nokia.com>2018-12-10 15:18:50 +0100
committerFilip Krzywka <filip.krzywka@nokia.com>2018-12-10 16:22:21 +0100
commita239958522a9edd0951854884dd11a7ef5513ca4 (patch)
tree76205b87d2795beee03557a9d0d0cae35324031a /sources/hv-collector-utils/src/main
parent8b8c37c296e55644063e0332fd455437168e78da (diff)
Add Markers logs
Change-Id: I5d3c9e1e4659782719e4847c5bcedbca39c173a0 Issue-ID: DCAEGEN2-669 Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-utils/src/main')
-rw-r--r--sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt43
-rw-r--r--sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt30
2 files changed, 73 insertions, 0 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 2fb48803..1e5c9c55 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
@@ -50,6 +50,9 @@ class Logger(logger: org.slf4j.Logger) {
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()) }
+
// WARN
fun withWarn(block: AtLevelLogger.() -> Unit) = warnLogger.block()
@@ -64,6 +67,8 @@ class Logger(logger: org.slf4j.Logger) {
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()) }
// INFO
@@ -79,6 +84,9 @@ class Logger(logger: org.slf4j.Logger) {
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()) }
+
// DEBUG
fun withDebug(block: AtLevelLogger.() -> Unit) = debugLogger.block()
@@ -93,6 +101,8 @@ class Logger(logger: org.slf4j.Logger) {
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()) }
// TRACE
@@ -108,11 +118,15 @@ class Logger(logger: org.slf4j.Logger) {
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()) }
+
}
abstract class AtLevelLogger {
abstract fun log(message: String)
abstract fun log(message: String, t: Throwable)
+ abstract fun log(marker: Marker, message: String)
open val enabled: Boolean
get() = true
@@ -138,8 +152,13 @@ object OffLevelLogger : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
// do not log anything
}
+
+ override fun log(marker: Marker, message: String) {
+ // do not log anything
+ }
}
+@Suppress("SuboptimalLoggerUsage")
class ErrorLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String) {
logger.error(message)
@@ -148,8 +167,13 @@ class ErrorLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
logger.error(message, t)
}
+
+ override fun log(marker: Marker, message: String) {
+ logger.error(marker(), message)
+ }
}
+@Suppress("SuboptimalLoggerUsage")
class WarnLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String) {
logger.warn(message)
@@ -158,8 +182,13 @@ class WarnLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
logger.warn(message, t)
}
+
+ override fun log(marker: Marker, message: String) {
+ logger.warn(marker(), message)
+ }
}
+@Suppress("SuboptimalLoggerUsage")
class InfoLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String) {
logger.info(message)
@@ -168,8 +197,13 @@ class InfoLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
logger.info(message, t)
}
+
+ override fun log(marker: Marker, message: String) {
+ logger.info(marker(), message)
+ }
}
+@Suppress("SuboptimalLoggerUsage")
class DebugLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String) {
logger.debug(message)
@@ -178,8 +212,13 @@ class DebugLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
logger.debug(message, t)
}
+
+ override fun log(marker: Marker, message: String) {
+ logger.debug(marker(), message)
+ }
}
+@Suppress("SuboptimalLoggerUsage")
class TraceLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String) {
logger.trace(message)
@@ -188,4 +227,8 @@ class TraceLevelLogger(private val logger: org.slf4j.Logger) : AtLevelLogger() {
override fun log(message: String, t: Throwable) {
logger.trace(message, t)
}
+
+ override fun log(marker: Marker, message: String) {
+ logger.trace(marker(), message)
+ }
}
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
new file mode 100644
index 00000000..83fb9a5e
--- /dev/null
+++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt
@@ -0,0 +1,30 @@
+/*
+ * ============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
+
+enum class Marker(private val marker: org.slf4j.Marker) {
+ ENTRY(MarkerFactory.getMarker("ENTRY")),
+ EXIT(MarkerFactory.getMarker("EXIT")),
+ INVOKE(MarkerFactory.getMarker("INVOKE"));
+
+ operator fun invoke() = marker
+}