From 9fbd0b5a8798606d00d34a93067b241ec6af552b Mon Sep 17 00:00:00 2001 From: xg353y Date: Mon, 13 Aug 2018 16:57:16 +0200 Subject: Update Logging Specifications Create our own logging constants to remove the dependency to org.onap.logging-analytics:logging-library Issue-ID: CLAMP-203, CLAMP-204, CLAMP-205 Change-Id: Id231dec1e91390f8f2d10a8eef03528da8ab9be5 Signed-off-by: xg353y --- .../org/onap/clamp/clds/service/CldsService.java | 2 +- .../clamp/clds/service/CldsTemplateService.java | 2 +- .../org/onap/clamp/clds/util/LoggingUtils.java | 23 ++- .../org/onap/clamp/clds/util/ONAPLogConstants.java | 192 +++++++++++++++++++++ 4 files changed, 204 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/onap/clamp/clds/util/ONAPLogConstants.java (limited to 'src/main/java/org/onap') diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 2139b3d39..bc58ee69f 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -74,7 +74,7 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; import org.onap.clamp.clds.transform.XslTransformer; import org.onap.clamp.clds.util.JacksonUtils; import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.clamp.clds.util.ONAPLogConstants; import org.slf4j.event.Level; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java index cca0afded..d82e7c6e7 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java @@ -33,7 +33,7 @@ import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.ValueItem; import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.clamp.clds.util.ONAPLogConstants; import org.slf4j.event.Level; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java index a20a70040..cdb2e29c5 100644 --- a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java +++ b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java @@ -45,7 +45,6 @@ import org.slf4j.event.Level; import org.springframework.security.core.context.SecurityContextHolder; import org.onap.clamp.clds.service.DefaultUserNameHandler; -import org.onap.logging.ref.slf4j.ONAPLogConstants; /** * This class handles the special info that appear in the log, like RequestID, @@ -58,8 +57,6 @@ public class LoggingUtils { /** String constant for messages ENTERING, EXITING, etc. */ private static final String EMPTY_MESSAGE = ""; - private static final String INVOCATIONID_OUT = "InvocationIDOut"; - private static final String TARGET_ENTITY = "TargetEngity"; /** Logger delegate. */ private EELFLogger mLogger; @@ -209,8 +206,8 @@ public class LoggingUtils { serviceName.equalsIgnoreCase(EMPTY_MESSAGE)) { MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI()); } - - this.mLogger.info("ENTRY"); + + this.mLogger.info(ONAPLogConstants.Markers.ENTRY); } /** @@ -224,7 +221,7 @@ public class LoggingUtils { MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, defaultToEmpty(descrption)); MDC.put(ONAPLogConstants.MDCs.RESPONSE_SEVERITY, defaultToEmpty(severity)); MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, defaultToEmpty(status)); - this.mLogger.info("EXIT"); + this.mLogger.info(ONAPLogConstants.Markers.EXIT); } finally { MDC.clear(); @@ -255,13 +252,13 @@ public class LoggingUtils { // Log INVOKE*, with the invocationID as the message body. // (We didn't really want this kind of behavior in the standard, // but is it worse than new, single-message MDC?) - this.mLogger.info("INVOKE"); - this.mLogger.info("INVOKE-" + ONAPLogConstants.InvocationMode.SYNCHRONOUS.toString() + "{"+ invocationID +"}"); + this.mLogger.info(ONAPLogConstants.Markers.INVOKE); + this.mLogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{"+ invocationID +"}"); return con; } public void invokeReturn() { // Add the Invoke-return marker and clear the needed MDC - this.mLogger.info("INVOKE-RETURN"); + this.mLogger.info(ONAPLogConstants.Markers.INVOKE_RETURN); invokeReturnContext(); } @@ -313,9 +310,9 @@ public class LoggingUtils { * @param invocationId The invocation ID */ private void invokeContext (String targetEntity, String targetServiceName, String invocationID) { - MDC.put(TARGET_ENTITY, defaultToEmpty(targetEntity)); + MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, defaultToEmpty(targetEntity)); MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, defaultToEmpty(targetServiceName)); - MDC.put(INVOCATIONID_OUT, invocationID); + MDC.put(ONAPLogConstants.MDCs.INVOCATIONID_OUT, invocationID); MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, ZonedDateTime.now(ZoneOffset.UTC) .format(DateTimeFormatter.ISO_INSTANT)); @@ -326,8 +323,8 @@ public class LoggingUtils { * */ private void invokeReturnContext () { - MDC.remove(TARGET_ENTITY); + MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY); MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME); - MDC.remove(INVOCATIONID_OUT); + MDC.remove(ONAPLogConstants.MDCs.INVOCATIONID_OUT); } } diff --git a/src/main/java/org/onap/clamp/clds/util/ONAPLogConstants.java b/src/main/java/org/onap/clamp/clds/util/ONAPLogConstants.java new file mode 100644 index 000000000..eea01a39a --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/util/ONAPLogConstants.java @@ -0,0 +1,192 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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.clamp.clds.util; + +/** + * Constants for standard ONAP headers, MDCs, etc. + */ +public final class ONAPLogConstants { + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Constructors. + // + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Hide and forbid construction. + */ + private ONAPLogConstants() { + throw new UnsupportedOperationException(); + } + + + /** + * Marker constants. + */ + public static final class Markers { + + /** Marker reporting invocation. */ + public static final String INVOKE = "INVOKE"; + + /** Marker reporting synchronous invocation. */ + public static final String INVOKE_RETURN = "INVOKE-RETURN"; + + /** Marker reporting synchronous invocation. */ + public static final String INVOKE_SYNC = "INVOKE-SYNCHRONOUS"; + + /** Marker reporting entry into a component. */ + public static final String ENTRY = "ENTRY"; + + /** Marker reporting exit from a component. */ + public static final String EXIT = "EXIT"; + + /** + * Hide and forbid construction. + */ + private Markers() { + throw new UnsupportedOperationException(); + } + } + + /** + * MDC name constants. + */ + public static final class MDCs { + + // Tracing. //////////////////////////////////////////////////////////// + + /** MDC correlating messages for an invocation. */ + public static final String INVOCATION_ID = "InvocationID"; + + /** MDC correlating messages for a logical transaction. */ + public static final String REQUEST_ID = "RequestID"; + + /** MDC recording calling service. */ + public static final String PARTNER_NAME = "PartnerName"; + + /** MDC recording current service. */ + public static final String SERVICE_NAME = "ServiceName"; + + /** MDC recording target service. */ + public static final String TARGET_SERVICE_NAME = "TargetServiceName"; + + /** MDC recording InvocationID Out. */ + public static final String INVOCATIONID_OUT = "InvocationIDOut"; + + /** MDC recording target entity. */ + public static final String TARGET_ENTITY = "TargetEngity"; + + /** MDC recording current service instance. */ + public static final String INSTANCE_UUID = "InstanceUUID"; + + // Network. //////////////////////////////////////////////////////////// + + /** MDC recording caller address. */ + public static final String CLIENT_IP_ADDRESS = "ClientIPAddress"; + + /** MDC recording server address. */ + public static final String SERVER_FQDN = "ServerFQDN"; + + /** + * MDC recording timestamp at the start of the current request, + * with the same scope as {@link #REQUEST_ID}. + * + *

Open issues: + *

+ *

+ * */ + public static final String ENTRY_TIMESTAMP = "EntryTimestamp"; + + /** MDC recording timestamp at the start of the current invocation. */ + public static final String INVOKE_TIMESTAMP = "InvokeTimestamp"; + + // Outcomes. /////////////////////////////////////////////////////////// + + /** MDC reporting outcome code. */ + public static final String RESPONSE_CODE = "ResponseCode"; + + /** MDC reporting outcome description. */ + public static final String RESPONSE_DESCRIPTION = "ResponseDescription"; + + /** MDC reporting outcome error level. */ + public static final String RESPONSE_SEVERITY = "Severity"; + + /** MDC reporting outcome error level. */ + public static final String RESPONSE_STATUS_CODE = "StatusCode"; + + // Unsorted. /////////////////////////////////////////////////////////// + + /** + * Hide and forbid construction. + */ + private MDCs() { + throw new UnsupportedOperationException(); + } + } + + /** + * Header name constants. + */ + public static final class Headers { + + /** HTTP X-ONAP-RequestID header. */ + public static final String REQUEST_ID = "X-ONAP-RequestID"; + + /** HTTP X-ONAP-InvocationID header. */ + public static final String INVOCATION_ID = "X-ONAP-InvocationID"; + + /** HTTP X-ONAP-PartnerName header. */ + public static final String PARTNER_NAME = "X-ONAP-PartnerName"; + + /** + * Hide and forbid construction. + */ + private Headers() { + throw new UnsupportedOperationException(); + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Enums. + // + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Response success or not, for setting StatusCode. + */ + public enum ResponseStatus { + + /** Success. */ + COMPLETED, + + /** Not. */ + ERROR, + } +} -- cgit 1.2.3-korg