summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-logger/src/main/java
diff options
context:
space:
mode:
authorKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-09-25 16:45:02 -0400
committerKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-09-25 16:45:13 -0400
commita8618399833e9e2c2cfdd214058234a1395f8361 (patch)
tree18d6ccbf962e8f191cd5163da2f39e96c7fd5202 /ecomp-sdk/epsdk-logger/src/main/java
parent7dda2debf352c4d89c468963c971dc0fd257eec8 (diff)
changes done to support logs format
Issue-ID: PORTAL-1008 Signed-off-by: Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com> Change-Id: I20f110c0fd48d7258f86f08501bad81244d3db20
Diffstat (limited to 'ecomp-sdk/epsdk-logger/src/main/java')
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java1
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java85
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java107
3 files changed, 154 insertions, 39 deletions
diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java
index 2eda82b0..80dbabde 100644
--- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java
+++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java
@@ -42,6 +42,7 @@ public enum AlarmSeverityEnum {
MAJOR("2"),
MINOR("3"),
INFORMATIONAL("4"),
+ ERROR("5"),
NONE("0");
private final String severity;
diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
index adad5caa..45eae6d4 100644
--- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
+++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
@@ -38,7 +38,6 @@
package org.onap.portalsdk.core.logging.logic;
import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
-import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
@@ -60,7 +59,6 @@ import org.onap.portalsdk.core.logging.format.AppMessagesEnum;
import org.onap.portalsdk.core.logging.format.ErrorSeverityEnum;
import org.slf4j.MDC;
-import com.att.eelf.configuration.Configuration;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.configuration.SLF4jWrapper;
@@ -115,17 +113,39 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
public void logWrite(EELFLogger logger, Level level, String msg, Throwable th, Object... arguments) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
setGlobalLoggingContext();
+ String requestId = null;
+ if (MDC.get(MDC_KEY_REQUEST_ID) == null||MDC.get(MDC_KEY_REQUEST_ID).isEmpty()){
+ requestId = UUID.randomUUID().toString();
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ }
+
if ( logger == errorLogger) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- MDC.put("ErrorCategory", ErrorSeverityEnum.ERROR.name());
- MDC.put("ErrorCode", "900");
- MDC.put("ErrorDescription", "Exception");
+ if(MDC.get(LoggerProperties.MDC_CLASS_NAME) == null) {
+ MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
+ }
+ MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.ERROR.name());
+ if(MDC.get(LoggerProperties.ERROR_CODE) == null) {
+ MDC.put(LoggerProperties.ERROR_CODE, "900");
+ }
+ if(MDC.get(LoggerProperties.ERROR_DESCRIPTION) == null) {
+ MDC.put(LoggerProperties.ERROR_DESCRIPTION, "Exception");
+ }
}
- if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
- String requestId = UUID.randomUUID().toString();
- MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
+ if(MDC.get(LoggerProperties.PARTNER_NAME) == null) {
+ MDC.put(LoggerProperties.PARTNER_NAME, "UNKNOWN");
+ }
+
+ if(MDC.get(LoggerProperties.STATUS_CODE) == null) {
+ MDC.put(LoggerProperties.STATUS_CODE, "COMPLETE");
+ }
+
+ if ( logger == auditLogger) {
+ MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
+ this.calculateDateTimeDifference(MDC.get(LoggerProperties.AUDITLOG_BEGIN_TIMESTAMP), MDC.get(LoggerProperties.AUDITLOG_END_TIMESTAMP));
+ MDC.put(LoggerProperties.CUSTOM_FIELD1, "EXIT");
+ MDC.put(LoggerProperties.CUSTOM_FIELD2, "InvocationID=" + requestId);
}
if (logger.isErrorEnabled()) {
@@ -135,12 +155,18 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
}
if ( logger == errorLogger) {
- MDC.remove(MDC_SERVICE_NAME);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- MDC.remove("ErrorCode");
- MDC.remove("ErrorDescription");
- MDC.remove("ErrorCategory");
+ MDC.remove(LoggerProperties.ERROR_CATAGORY);
+ MDC.remove(LoggerProperties.ERROR_CODE);
+ MDC.remove(LoggerProperties.ERROR_DESCRIPTION);
}
+
+ if(logger == auditLogger) {
+ MDC.remove(LoggerProperties.MDC_CLASS_NAME);
+ MDC.remove(LoggerProperties.CUSTOM_FIELD1);
+ MDC.remove(LoggerProperties.CUSTOM_FIELD2);
+ }
+ MDC.remove(MDC_KEY_REQUEST_ID);
}
@@ -322,9 +348,8 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
/**
* Initializes the logger context.
*/
- public void init(String appName) {
+ public void init() {
setGlobalLoggingContext();
- MDC.put(MDC_SERVICE_NAME, appName);
}
public static String getCurrentDateTimeUTC() {
@@ -345,9 +370,9 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();
ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();
- MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());
- MDC.put("ErrorCode", epMessageEnum.getErrorCode());
- MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());
+ MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.severity());
+ MDC.put(LoggerProperties.ERROR_CODE, epMessageEnum.getErrorCode());
+ MDC.put(LoggerProperties.ERROR_DESCRIPTION, epMessageEnum.getErrorDescription());
String resolution = this.formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(),
(Object[]) param);
@@ -361,8 +386,8 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
} catch (Exception e) {
errorLogger.error("logEcompError failed", e);
} finally {
- MDC.remove("ErrorCode");
- MDC.remove("ErrorDescription");
+ MDC.remove(LoggerProperties.ERROR_CODE);
+ MDC.remove(LoggerProperties.ERROR_DESCRIPTION);
MDC.remove(MDC_ALERT_SEVERITY);
}
}
@@ -395,7 +420,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
try {
MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- MDC.put(MDC_INSTANCE_UUID, LoggerProperties.getProperty(LoggerProperties.INSTANCE_UUID));
+ MDC.put(MDC_SERVICE_NAME, LoggerProperties.getPropertyValue(LoggerProperties.APP_NAME));
} catch (Exception e) {
errorLogger.error("setGlobalLoggingContext failed", e);
}
@@ -484,4 +509,22 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
}
return "";
}
+
+ /**
+ *
+ * @param beginDateTime
+ * @param endDateTime
+ */
+ private void calculateDateTimeDifference(String beginDateTime, String endDateTime) {
+ if (beginDateTime != null && endDateTime != null) {
+ try {
+ Date beginDate = ecompLogDateFormat.parse(beginDateTime);
+ Date endDate = ecompLogDateFormat.parse(endDateTime);
+ String timeDifference = String.format("%d", endDate.getTime() - beginDate.getTime());
+ MDC.put(LoggerProperties.MDC_TIMER, timeDifference);
+ } catch (Exception e) {
+ errorLogger.error("calculateDateTimeDifference failed", e);
+ }
+ }
+ }
}
diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
index abd98b19..4287088b 100644
--- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
+++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
@@ -37,13 +37,24 @@
*/
package org.onap.portalsdk.core.logging.logic;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.springframework.util.ResourceUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
public class LoggerProperties {
-
public static final String MDC_APPNAME = "AppName";
public static final String MDC_REST_PATH = "RestPath";
public static final String MDC_REST_METHOD = "RestMethod";
@@ -62,20 +73,34 @@ public class LoggerProperties {
public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
public static final String STATUS_CODE = "StatusCode";
public static final String RESPONSE_CODE = "ResponseCode";
-
+
public static final String HTTP = "HTTP";
public static final String HTTPS = "HTTPS";
public static final String UNKNOWN = "Unknown";
public static final String PROTOCOL = "PROTOCOL";
public static final String USERAGENT_NAME = "user-agent";
public static final String USER_ATTRIBUTE_NAME = "user_attribute_name";
-
- private LoggerProperties(){}
+ public static final String ALERT_SEVERITY = "AlertSeverity";
+ public static final String ERROR_CATAGORY = "ErrorCatagory";
+ public static final String ERROR_CODE = "ErrorCode";
+ public static final String ERROR_DESCRIPTION = "ErrorDescription";
+ public static final String CUSTOM_FIELD1 = "CustomField1";
+ public static final String CUSTOM_FIELD2 = "CustomField2";
+ public static final String APP_NAME = "application_name";
+
+ private LoggerProperties() {
+ }
+
+ private static Properties properties;
+
+ private static DocumentBuilderFactory dbFactory;
+
+ private static DocumentBuilder dBuilder;
+
+ private static Document doc;
- private static Properties properties;
-
- private static String propertyFileName = "logger.properties";
+ private static String propertyFileName = "classpath:logback.xml";
private static final Object lockObject = new Object();
@@ -83,8 +108,7 @@ public class LoggerProperties {
* Gets the property value for the specified key. If a value is found, leading
* and trailing space is trimmed.
*
- * @param property
- * Property key
+ * @param property Property key
* @return Value for the named property; null if the property file was not
* loaded or the key was not found.
*/
@@ -113,21 +137,68 @@ public class LoggerProperties {
* whether the properties file can be loaded successfully.
*
* @return True if properties were successfully loaded, else false.
- * @throws IOException
- * On failure
+ * @throws IOException On failure
+ * @throws SAXException
+ * @throws ParserConfigurationException
*/
private static boolean initialize() throws IOException {
- if (properties != null)
+ File xmlFile = null;
+// if (properties != null)
+// return true;
+// InputStream in = LoggerProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
+
+ if (dbFactory != null)
return true;
- InputStream in = LoggerProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
- if (in == null)
- return false;
- properties = new Properties();
+// if (in == null)
+// return false;
+ if (dbFactory == null)
+// properties = new Properties();
+ dbFactory = DocumentBuilderFactory.newInstance();
try {
- properties.load(in);
+// properties.load(in);
+ xmlFile = ResourceUtils.getFile(propertyFileName);
+ dBuilder = dbFactory.newDocumentBuilder();
+ doc = dBuilder.parse(xmlFile);
+ doc.getDocumentElement().normalize();
+ } catch (IOException | SAXException | ParserConfigurationException e) {
+ return false;
} finally {
- in.close();
+// in.close();
}
return true;
}
+
+ public static String getPropertyValue(String propertyName) {
+
+ if (dbFactory == null) {
+ synchronized (lockObject) {
+ try {
+ if (!initialize()) {
+ return null;
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+ }
+ String value = getValue(doc, propertyName);
+ if (value != null)
+ value = value.trim();
+ return value;
+
+ }
+
+ private static String getValue(Document someNode, String property) {
+ NodeList nodeList = someNode.getElementsByTagName("property");
+ String Value = null;
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element) {
+ if (((Element) node).getAttribute("name").toString().equals(property)) {
+ Value = ((Element) node).getAttribute("value").toString();
+ }
+ }
+ }
+ return Value;
+ }
} \ No newline at end of file