summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java')
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java280
1 files changed, 128 insertions, 152 deletions
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 901c6737..2bb1b526 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
@@ -1,39 +1,39 @@
/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software 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.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * 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============================================
- *
- *
+* ============LICENSE_START==========================================
+* ONAP Portal SDK
+* ===================================================================
+* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+* ===================================================================
+*
+* Unless otherwise specified, all software contained herein is licensed
+* under the Apache License, Version 2.0 (the "License");
+* you may not use this software 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.
+*
+* Unless otherwise specified, all documentation contained herein is licensed
+* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+* you may not use this documentation except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* https://creativecommons.org/licenses/by/4.0/
+*
+* Unless required by applicable law or agreed to in writing, documentation
+* 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.portalsdk.core.logging.logic;
@@ -49,6 +49,8 @@ import java.net.InetAddress;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -71,7 +73,6 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
public static final EELFLogger applicationLogger = EELFManager.getInstance().getApplicationLogger();
public static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
private static final SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-
private String className;
private static ConcurrentMap<String, EELFLoggerDelegate> classMap = new ConcurrentHashMap<String, EELFLoggerDelegate>();
@@ -97,8 +98,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* Gets a logger for the specified class name. If the logger does not already
* exist in the map, this creates a new logger.
*
- * @param className
- * If null or empty, uses EELFLoggerDelegate as the class name.
+ * @param className If null or empty, uses EELFLoggerDelegate as the class name.
* @return Instance of EELFLoggerDelegate
*/
public static EELFLoggerDelegate getLogger(final String className) {
@@ -112,6 +112,28 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
return delegate;
}
+ public static void logWrite(EELFLogger logger, Level level, String msg, Throwable th, Object... arguments) {
+
+ if ( logger == errorLogger) {
+ MDC.put("ErrorCategory", ErrorSeverityEnum.ERROR.name());
+ MDC.put("ErrorCode", "900");
+ MDC.put("ErrorDescription", "Exception");
+ }
+
+ if (logger.isErrorEnabled()) {
+ logger.log(level, msg, null, arguments);
+ } else {
+ logger.log(level, msg, th, arguments);
+ }
+
+ if ( logger == errorLogger) {
+ MDC.remove("ErrorCode");
+ MDC.remove("ErrorDescription");
+ MDC.remove("ErrorCategory");
+ }
+
+ }
+
/**
* Logs a message at the lowest level: trace.
*
@@ -119,11 +141,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param msg
*/
public void trace(EELFLogger logger, String msg) {
- if (logger.isTraceEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.trace(msg);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.TRACE, msg, null);
}
/**
@@ -134,11 +152,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param arguments
*/
public void trace(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isTraceEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.trace(msg, arguments);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.TRACE, msg, null, arguments);
}
/**
@@ -149,11 +163,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param th
*/
public void trace(EELFLogger logger, String msg, Throwable th) {
- if (logger.isTraceEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.trace(msg, th);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.TRACE, msg, null, th);
}
/**
@@ -163,11 +173,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param msg
*/
public void debug(EELFLogger logger, String msg) {
- if (logger.isDebugEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.debug(msg);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.DEBUG, msg, null);
}
/**
@@ -178,11 +184,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param arguments
*/
public void debug(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isDebugEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.debug(msg, arguments);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.DEBUG, msg, null, arguments);
}
/**
@@ -193,11 +195,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param th
*/
public void debug(EELFLogger logger, String msg, Throwable th) {
- if (logger.isDebugEnabled()) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.debug(msg, th);
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- }
+ logWrite(logger, Level.DEBUG, msg, null, th);
}
/**
@@ -208,7 +206,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void info(EELFLogger logger, String msg) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.info(msg);
+ logWrite(logger, Level.INFO, msg, null);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -221,8 +219,9 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void info(EELFLogger logger, String msg, Object... arguments) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.info(msg, arguments);
+ logWrite(logger, Level.INFO, msg, null, arguments);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
+
}
/**
@@ -234,8 +233,9 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void info(EELFLogger logger, String msg, Throwable th) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.info(msg, th);
+ logWrite(logger, Level.INFO, msg, null, th);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
+
}
/**
@@ -246,7 +246,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void warn(EELFLogger logger, String msg) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.warn(msg);
+ logWrite(logger, Level.WARN, msg, null);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -259,7 +259,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void warn(EELFLogger logger, String msg, Object... arguments) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, arguments);
+ logWrite(logger, Level.WARN, msg, null, arguments);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -272,7 +272,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void warn(EELFLogger logger, String msg, Throwable th) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, th);
+ logWrite(logger, Level.WARN, msg, null, th);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -284,7 +284,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void error(EELFLogger logger, String msg) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.error(msg);
+ logWrite(logger, Level.ERROR, msg, null);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -297,7 +297,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void error(EELFLogger logger, String msg, Object... arguments) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.error(msg, arguments);
+ logWrite(logger, Level.ERROR, msg, null, arguments);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -310,7 +310,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
*/
public void error(EELFLogger logger, String msg, Throwable th) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.error(msg, th);
+ logWrite(logger, Level.ERROR, msg, null);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
}
@@ -324,44 +324,24 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
public void error(EELFLogger logger, String msg, AlarmSeverityEnum severtiy) {
MDC.put(MDC_ALERT_SEVERITY, severtiy.name());
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
- logger.error(msg);
- MDC.remove(MDC_ALERT_SEVERITY);
+ logWrite(logger, Level.ERROR, msg, null);
MDC.remove(LoggerProperties.MDC_CLASS_NAME);
+ MDC.remove(MDC_ALERT_SEVERITY);
}
/**
* Initializes the logger context.
*/
- public void init() {
+ public void init(String appName) {
setGlobalLoggingContext();
- final String msg = "############################ Logging is started. ############################";
- // These loggers emit the current date-time without being told.
- info(applicationLogger, msg);
- error(errorLogger, msg);
- debug(debugLogger, msg);
- // Audit and metrics logger must be told start AND stop times
- final String currentDateTime = getCurrentDateTimeUTC();
- // Set the MDC with audit properties
- MDC.put(LoggerProperties.AUDITLOG_BEGIN_TIMESTAMP, currentDateTime);
- MDC.put(LoggerProperties.AUDITLOG_END_TIMESTAMP, currentDateTime);
- info(auditLogger, msg);
- MDC.remove(LoggerProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(LoggerProperties.AUDITLOG_END_TIMESTAMP);
- // Set the MDC with metrics properties
- MDC.put(LoggerProperties.METRICSLOG_BEGIN_TIMESTAMP, currentDateTime);
- MDC.put(LoggerProperties.METRICSLOG_END_TIMESTAMP, currentDateTime);
- info(metricsLogger, msg);
- MDC.remove(LoggerProperties.METRICSLOG_BEGIN_TIMESTAMP);
- MDC.remove(LoggerProperties.METRICSLOG_END_TIMESTAMP);
+ MDC.put(MDC_SERVICE_NAME, appName);
}
-
-
+
public static String getCurrentDateTimeUTC() {
String currentDateTime = ecompLogDateFormat.format(new Date());
return currentDateTime;
}
-
/**
* Logs a standard message identified by the specified enum, using the specified
* parameters, at error level. Alarm and error severity are taken from the
@@ -451,60 +431,56 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
* @param req
* @param appName
*/
- public void setRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest req, String appName,String reqId,String loginId) {// Load the default fields
+ public void setRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest req, String appName, String reqId,
+ String loginId) {// Load the default fields
// Load the default fields
- setGlobalLoggingContext();
-
- // Load the request based fields
- if (req != null) {
- // Load the Request into MDC context.
-
- MDC.put(MDC_KEY_REQUEST_ID, reqId);
-
- // Load user agent into MDC context, if available.
- String accessingClient = req.getHeader(LoggerProperties.USERAGENT_NAME);
- if (accessingClient != null && !"".equals(accessingClient) && (accessingClient.contains("Mozilla")
- || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) {
- accessingClient = appName + "_FE";
- }
- MDC.put(LoggerProperties.PARTNER_NAME, accessingClient);
-
- // Protocol, Rest URL & Rest Path
- MDC.put(LoggerProperties.FULL_URL, LoggerProperties.UNKNOWN);
- MDC.put(LoggerProperties.PROTOCOL, LoggerProperties.HTTP);
- String restURL = getFullURL(req);
- if (restURL != null && restURL != "") {
- MDC.put(LoggerProperties.FULL_URL, restURL);
- if (restURL.toLowerCase().contains("https")) {
- MDC.put(LoggerProperties.PROTOCOL, LoggerProperties.HTTPS);
- }
- }
-
- // Rest Path
- MDC.put(MDC_SERVICE_NAME, req.getServletPath());
-
- // Client IPAddress i.e. IPAddress of the remote host who is making
- // this request.
- String clientIPAddress = req.getHeader("X-FORWARDED-FOR");
- if (clientIPAddress == null) {
- clientIPAddress = req.getRemoteAddr();
- }
- MDC.put(LoggerProperties.CLIENT_IP_ADDRESS, clientIPAddress);
-
- // Load loginId into MDC context.
- MDC.put(LoggerProperties.MDC_LOGIN_ID, "Unknown");
-
-
-
- if (loginId != null && loginId != "") {
- MDC.put(LoggerProperties.MDC_LOGIN_ID, loginId);
- }
+ setGlobalLoggingContext();
+
+ // Load the request based fields
+ if (req != null) {
+ // Load the Request into MDC context.
+
+ MDC.put(MDC_KEY_REQUEST_ID, reqId);
+
+ // Load user agent into MDC context, if available.
+ String accessingClient = req.getHeader(LoggerProperties.USERAGENT_NAME);
+ if (accessingClient != null && !"".equals(accessingClient) && (accessingClient.contains("Mozilla")
+ || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) {
+ accessingClient = appName + "_FE";
+ }
+ MDC.put(LoggerProperties.PARTNER_NAME, accessingClient);
+
+ // Protocol, Rest URL & Rest Path
+ MDC.put(LoggerProperties.FULL_URL, LoggerProperties.UNKNOWN);
+ MDC.put(LoggerProperties.PROTOCOL, LoggerProperties.HTTP);
+ String restURL = getFullURL(req);
+ if (restURL != null && restURL != "") {
+ MDC.put(LoggerProperties.FULL_URL, restURL);
+ if (restURL.toLowerCase().contains("https")) {
+ MDC.put(LoggerProperties.PROTOCOL, LoggerProperties.HTTPS);
}
+ }
+
+ // Rest Path
+ MDC.put(MDC_SERVICE_NAME, req.getServletPath());
+
+ // Client IPAddress i.e. IPAddress of the remote host who is making
+ // this request.
+ String clientIPAddress = req.getHeader("X-FORWARDED-FOR");
+ if (clientIPAddress == null) {
+ clientIPAddress = req.getRemoteAddr();
+ }
+ MDC.put(LoggerProperties.CLIENT_IP_ADDRESS, clientIPAddress);
+
+ // Load loginId into MDC context.
+ MDC.put(LoggerProperties.MDC_LOGIN_ID, "Unknown");
+
+ if (loginId != null && loginId != "") {
+ MDC.put(LoggerProperties.MDC_LOGIN_ID, loginId);
+ }
+ }
}
-
-
-
public static String getFullURL(HttpServletRequest request) {
if (request != null) {
StringBuffer requestURL = request.getRequestURL();