aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-07 13:42:39 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-07 13:42:39 +0200
commit717018f3d1d8ef2a6f9b7e45be57a75eb7ea7050 (patch)
tree62d998e3133e305fe957d24f1e5ac60b4c10a677 /app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java
parenta3e692a4e0309342f8c8f60ce8fdeb0d2f14ab5c (diff)
Adjust history package name to use org.onap.portalng instead of org.onap.portal
Issue-ID: PORTALNG-92 Change-Id: I67f5a75834960ace8cb5ee6846c6741dc69fde2f Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java')
-rw-r--r--app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java b/app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java
new file mode 100644
index 0000000..90c61c4
--- /dev/null
+++ b/app/src/main/java/org/onap/portalng/history/logging/LoggingHelper.java
@@ -0,0 +1,68 @@
+/*
+ *
+ * Copyright (c) 2023. Deutsche Telekom AG
+ *
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ *
+ */
+
+package org.onap.portalng.history.logging;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.slf4j.Logger;
+import org.slf4j.MDC;
+
+import java.util.Map;
+import java.util.function.BiConsumer;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class LoggingHelper {
+ public static void error(
+ Logger logger, Map<LogContextVariable, String> metadata, String message, Object... args) {
+ log(logger::error, metadata, message, args);
+ }
+
+ public static void debug(
+ Logger logger, Map<LogContextVariable, String> metadata, String message, Object... args) {
+ log(logger::debug, metadata, message, args);
+ }
+
+ public static void info(
+ Logger logger, Map<LogContextVariable, String> metadata, String message, Object... args) {
+ log(logger::info, metadata, message, args);
+ }
+
+ public static void warn(
+ Logger logger, Map<LogContextVariable, String> metadata, String message, Object... args) {
+ log(logger::warn, metadata, message, args);
+ }
+
+ public static void trace(
+ Logger logger, Map<LogContextVariable, String> metadata, String message, Object... args) {
+ log(logger::trace, metadata, message, args);
+ }
+
+ private static void log(
+ BiConsumer<String, Object[]> logMethod,
+ Map<LogContextVariable, String> metadata,
+ String message,
+ Object... args) {
+ metadata.forEach((variable, value) -> MDC.put(variable.getVariableName(), value));
+ logMethod.accept(message, args);
+ MDC.clear();
+ }
+}