Update Logging Specifications 29/60329/5
authorxg353y <xg353y@intl.att.com>
Mon, 13 Aug 2018 14:57:16 +0000 (16:57 +0200)
committerxg353y <xg353y@intl.att.com>
Tue, 14 Aug 2018 14:11:27 +0000 (16:11 +0200)
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 <xg353y@intl.att.com>
pom.xml
src/main/java/org/onap/clamp/clds/service/CldsService.java
src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
src/main/java/org/onap/clamp/clds/util/ONAPLogConstants.java [new file with mode: 0644]
src/main/resources/logback-default.xml

diff --git a/pom.xml b/pom.xml
index 6c37666..026eb5c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -68,7 +68,6 @@
                                <java.version>1.8</java.version>
 
                                <eelf.core.version>1.0.0</eelf.core.version>
-                               <logging.analytics.version>1.2.2-SNAPSHOT</logging.analytics.version>
                                <camel.version>2.22.0</camel.version>
                                <springboot.version>2.0.2.RELEASE</springboot.version>
 
                                                <artifactId>eelf-core</artifactId>
                                                <version>${eelf.core.version}</version>
                                </dependency>
-                               <dependency>
-                                               <groupId>org.onap.logging-analytics</groupId>
-                                               <artifactId>logging-library</artifactId>
-                                               <version>${logging.analytics.version}</version>
-                               </dependency>
                                <dependency>
                                                <groupId>org.codehaus.janino</groupId>
                                                <artifactId>janino</artifactId>
index 2139b3d..bc58ee6 100644 (file)
@@ -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;
index cca0afd..d82e7c6 100644 (file)
@@ -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;
index a20a700..cdb2e29 100644 (file)
@@ -45,7 +45,6 @@ import org.slf4j.event.Level;
 import org.springframework.security.core.context.SecurityContextHolder;\r
 \r
 import org.onap.clamp.clds.service.DefaultUserNameHandler;\r
-import org.onap.logging.ref.slf4j.ONAPLogConstants;\r
 \r
 /**\r
  * This class handles the special info that appear in the log, like RequestID,\r
@@ -58,8 +57,6 @@ public class LoggingUtils {
 \r
     /** String constant for messages <tt>ENTERING</tt>, <tt>EXITING</tt>, etc. */\r
     private static final String EMPTY_MESSAGE = "";\r
-    private static final String INVOCATIONID_OUT = "InvocationIDOut";\r
-    private static final String TARGET_ENTITY = "TargetEngity";\r
 \r
     /** Logger delegate. */\r
     private EELFLogger mLogger;\r
@@ -209,8 +206,8 @@ public class LoggingUtils {
                        serviceName.equalsIgnoreCase(EMPTY_MESSAGE)) {\r
             MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI());\r
         }\r
-        \r
-        this.mLogger.info("ENTRY");\r
+\r
+        this.mLogger.info(ONAPLogConstants.Markers.ENTRY);\r
     }\r
 \r
     /**\r
@@ -224,7 +221,7 @@ public class LoggingUtils {
             MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, defaultToEmpty(descrption));\r
             MDC.put(ONAPLogConstants.MDCs.RESPONSE_SEVERITY, defaultToEmpty(severity));\r
             MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, defaultToEmpty(status));\r
-            this.mLogger.info("EXIT");\r
+            this.mLogger.info(ONAPLogConstants.Markers.EXIT);\r
         }\r
         finally {\r
             MDC.clear();\r
@@ -255,13 +252,13 @@ public class LoggingUtils {
         // Log INVOKE*, with the invocationID as the message body.\r
         // (We didn't really want this kind of behavior in the standard,\r
         // but is it worse than new, single-message MDC?)\r
-        this.mLogger.info("INVOKE");\r
-        this.mLogger.info("INVOKE-" + ONAPLogConstants.InvocationMode.SYNCHRONOUS.toString() + "{"+ invocationID +"}");\r
+        this.mLogger.info(ONAPLogConstants.Markers.INVOKE);\r
+        this.mLogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{"+ invocationID +"}");\r
         return con;\r
     }\r
     public void invokeReturn() {\r
         // Add the Invoke-return marker and clear the needed MDC\r
-        this.mLogger.info("INVOKE-RETURN");\r
+        this.mLogger.info(ONAPLogConstants.Markers.INVOKE_RETURN);\r
         invokeReturnContext();\r
     }\r
 \r
@@ -313,9 +310,9 @@ public class LoggingUtils {
      * @param invocationId The invocation ID\r
      */\r
     private void invokeContext (String targetEntity, String targetServiceName, String invocationID) {\r
-        MDC.put(TARGET_ENTITY, defaultToEmpty(targetEntity));\r
+        MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, defaultToEmpty(targetEntity));\r
         MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, defaultToEmpty(targetServiceName));\r
-        MDC.put(INVOCATIONID_OUT, invocationID);\r
+        MDC.put(ONAPLogConstants.MDCs.INVOCATIONID_OUT, invocationID);\r
         MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,\r
                 ZonedDateTime.now(ZoneOffset.UTC)\r
                         .format(DateTimeFormatter.ISO_INSTANT));\r
@@ -326,8 +323,8 @@ public class LoggingUtils {
      *\r
      */\r
     private void invokeReturnContext () {\r
-        MDC.remove(TARGET_ENTITY);\r
+        MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY);\r
         MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);\r
-        MDC.remove(INVOCATIONID_OUT);\r
+        MDC.remove(ONAPLogConstants.MDCs.INVOCATIONID_OUT);\r
     }\r
 }\r
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 (file)
index 0000000..eea01a3
--- /dev/null
@@ -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}.
+         *
+         * <p>Open issues:
+         * <ul>
+         *     <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul>
+         *     <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul>
+         *     <ul>Whatever mechanism we define, it's going to be costly.</ul>
+         * </ul>
+         * </p>
+         * */
+        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 <tt>X-ONAP-RequestID</tt> header. */
+        public static final String REQUEST_ID = "X-ONAP-RequestID";
+
+        /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
+        public static final String INVOCATION_ID = "X-ONAP-InvocationID";
+
+        /** HTTP <tt>X-ONAP-PartnerName</tt> 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 <tt>StatusCode</tt>.
+     */
+    public enum ResponseStatus {
+
+        /** Success. */
+        COMPLETED,
+
+        /** Not. */
+        ERROR,
+    }
+}
index 7e8eba5..37cdf76 100644 (file)
@@ -10,6 +10,7 @@
                <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/>
                <property name="p_thr" value="%thread"/>
                <property name="defaultPattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/>
+               <property name="debugPattern" value="%nopexception${p_tim}|${p_lvl}|${p_mdc}|{p_exc}|%msg%n"/>
 
                <!-- Example evaluator filter applied against console appender -->
                <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
@@ -20,7 +21,7 @@
                                                <level>INFO</level>
                                </filter>
                                <encoder>
-                                               <pattern>${defaultPattern}</pattern>
+                                               <pattern>${debugPattern}</pattern>
                                </encoder>
                </appender>
 
@@ -51,7 +52,7 @@
                                <file>${logDirectory}/debug.log</file>
                                <append>true</append>
                                <encoder>
-                                               <pattern>${defaultPattern}</pattern>
+                                               <pattern>${debugPattern}</pattern>
                                </encoder>
                                <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                                        <fileNamePattern>${outputDirectory}/clamp/debug.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>