aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-27 23:15:20 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-29 07:14:46 +0000
commitbe66acfea37b8d96cbb1b1e14592de57ec3bc4ae (patch)
treee165dfbff79534693b1cebdf67542151963100de
parent269abccbd334bb5bcfdb7d22c56ffcebc201d512 (diff)
Reformat common-app-logging
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3449 Change-Id: I473b6588c94bcee3b6e2c31d15664b3930f804df
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogConfiguration.java50
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java66
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java12
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java10
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java909
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java61
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java21
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java44
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java15
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java11
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java30
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java2
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java4
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java5
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java15
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java7
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java2
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java9
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java7
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java3
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java29
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java238
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java152
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java62
24 files changed, 801 insertions, 963 deletions
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogConfiguration.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogConfiguration.java
index 6862fdddc3..024dcc1aa4 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogConfiguration.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogConfiguration.java
@@ -2,28 +2,28 @@ package org.openecomp.sdc.common.log.api;
public interface ILogConfiguration {
- String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceID";
- String MDC_SERVER_IP_ADDRESS = "ServerIPAddress";
- String MDC_REMOTE_HOST = "RemoteHost";
- String MDC_AUDIT_MESSAGE = "AuditMessage";
- String MDC_END_TIMESTAMP = "EndTimestamp";
- String MDC_ELAPSED_TIME = "ElapsedTime";
- String MDC_PROCESS_KEY = "ProcessKey";
- String MDC_TARGET_VIRTUAL_ENTITY = "TargetVirtualEntity";
- String MDC_ERROR_CATEGORY = "ErrorCategory";
- String MDC_ERROR_CODE = "ErrorCode";
- String MDC_ERROR_DESC = "ErrorDescription";
- String MDC_CLASS_NAME = "ClassName";
- String MDC_OPT_FIELD1 = "CustomField1";
- String MDC_OPT_FIELD2 = "CustomField2";
- String MDC_OPT_FIELD3 = "CustomField3";
- String MDC_OPT_FIELD4 = "CustomField4";
- String MDC_OUTGOING_INVOCATION_ID = "OutgoingInvocationId";
- String MDC_SUPPORTABLITY_ACTION = "SupportablityAction";
- String MDC_SUPPORTABLITY_CSAR_UUID="SupportablityCsarUUID";
- String MDC_SUPPORTABLITY_CSAR_VERSION="SupportablityCsarVersion";
- String MDC_SUPPORTABLITY_COMPONENT_NAME = "SupportablityComponentName";
- String MDC_SUPPORTABLITY_COMPONENT_UUID = "SupportablityComponentUUID";
- String MDC_SUPPORTABLITY_COMPONENT_VERSION="SupportablityComponentVersion";
- String MDC_SUPPORTABLITY_STATUS_CODE = "SupportablityStatus";
-} \ No newline at end of file
+ String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceID";
+ String MDC_SERVER_IP_ADDRESS = "ServerIPAddress";
+ String MDC_REMOTE_HOST = "RemoteHost";
+ String MDC_AUDIT_MESSAGE = "AuditMessage";
+ String MDC_END_TIMESTAMP = "EndTimestamp";
+ String MDC_ELAPSED_TIME = "ElapsedTime";
+ String MDC_PROCESS_KEY = "ProcessKey";
+ String MDC_TARGET_VIRTUAL_ENTITY = "TargetVirtualEntity";
+ String MDC_ERROR_CATEGORY = "ErrorCategory";
+ String MDC_ERROR_CODE = "ErrorCode";
+ String MDC_ERROR_DESC = "ErrorDescription";
+ String MDC_CLASS_NAME = "ClassName";
+ String MDC_OPT_FIELD1 = "CustomField1";
+ String MDC_OPT_FIELD2 = "CustomField2";
+ String MDC_OPT_FIELD3 = "CustomField3";
+ String MDC_OPT_FIELD4 = "CustomField4";
+ String MDC_OUTGOING_INVOCATION_ID = "OutgoingInvocationId";
+ String MDC_SUPPORTABLITY_ACTION = "SupportablityAction";
+ String MDC_SUPPORTABLITY_CSAR_UUID = "SupportablityCsarUUID";
+ String MDC_SUPPORTABLITY_CSAR_VERSION = "SupportablityCsarVersion";
+ String MDC_SUPPORTABLITY_COMPONENT_NAME = "SupportablityComponentName";
+ String MDC_SUPPORTABLITY_COMPONENT_UUID = "SupportablityComponentUUID";
+ String MDC_SUPPORTABLITY_COMPONENT_VERSION = "SupportablityComponentVersion";
+ String MDC_SUPPORTABLITY_STATUS_CODE = "SupportablityStatus";
+}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java
index ed1a19d76d..00e0c09aee 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java
@@ -6,6 +6,7 @@ import org.openecomp.sdc.common.log.enums.Severity;
* Created by dd4296 on 12/25/2017.
*/
public interface ILogFieldsHandler {
+
void startAuditTimer();
void startMetricTimer();
@@ -36,42 +37,36 @@ public interface ILogFieldsHandler {
void setOutgoingInvocationId(String outgoingInvocationId);
- void setKeyRequestId(String keyRequestId);
-
- void setRemoteHost(String remoteHost);
-
- void setServiceName(String serviceName);
-
void setStatusCode(String statusCode);
- void setPartnerName(String partnerName);
-
void setResponseCode(int responseCode);
void setResponseDesc(String responseDesc);
void setServiceInstanceId(String serviceInstanceId);
- void setTargetEntity(String targetEntity);
-
- void setTargetServiceName(String targetServiceName);
-
void setTargetVirtualEntity(String targetVirtualEntity);
- void setErrorCode(int errorCode);
-
- void setErrorCategory(String errorCategory);
-
String getErrorCode();
+ void setErrorCode(int errorCode);
+
String getServiceName();
+ void setServiceName(String serviceName);
+
String getTargetEntity();
+ void setTargetEntity(String targetEntity);
+
String getTargetServiceName();
+ void setTargetServiceName(String targetServiceName);
+
String getErrorCategory();
+ void setErrorCategory(String errorCategory);
+
void clear();
boolean isMDCParamEmpty(String mdcKeyName);
@@ -82,6 +77,8 @@ public interface ILogFieldsHandler {
String getKeyRequestId();
+ void setKeyRequestId(String keyRequestId);
+
void removeStatusCode();
void removePartnerName();
@@ -104,38 +101,37 @@ public interface ILogFieldsHandler {
void removeErrorDescription();
- void setAuditMessage(String message);
-
String getAuditMessage();
- //service supportability [US 496441]
+ void setAuditMessage(String message);
+ //service supportability [US 496441]
String getSupportablityAction();
- String getSupportablityCsarUUID();
-
- String getSupportablityCsarVersion();
-
- String getSupportablityComponentName();
-
- String getSupportablityComponentUUID();
-
- String getSupportablityComponentVersion();
-
- String getSupportablityStatusCode();
-
void setSupportablityAction(String action);
+ String getSupportablityCsarUUID();
+
void setSupportablityCsarUUID(String uuid);
+ String getSupportablityCsarVersion();
+
void setSupportablityCsarVersion(String version);
+ String getSupportablityComponentName();
+
void setSupportablityComponentName(String name);
+ String getSupportablityComponentUUID();
+
void setSupportablityComponentUUID(String UUID);
+ String getSupportablityComponentVersion();
+
void setSupportablityComponentVersion(String version);
+ String getSupportablityStatusCode();
+
void setSupportablityStatusCode(String statusCode);
void removeSupportablityAction();
@@ -154,11 +150,15 @@ public interface ILogFieldsHandler {
String getPartnerName();
+ void setPartnerName(String partnerName);
+
String getRemoteHost();
- String getServerIpAddress();
+ void setRemoteHost(String remoteHost);
- void setKeyInvocationId(String invocationId);
+ String getServerIpAddress();
CharSequence getKeyInvocationId();
+
+ void setKeyInvocationId(String invocationId);
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java
index 9a2ad6960a..1a3a8c5e90 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java
@@ -1,22 +1,30 @@
package org.openecomp.sdc.common.log.api;
+import java.util.List;
import org.openecomp.sdc.common.log.enums.LogLevel;
import org.slf4j.Marker;
-import java.util.List;
-
/**
* Created by dd4296 on 12/24/2017.
*/
public interface ILogger {
+
void log(LogLevel logLevel, String message);
+
void log(Marker marker, LogLevel logLevel, String message);
+
void log(LogLevel logLevel, String message, Object... params);
+
void log(Marker marker, LogLevel logLevel, String message, Object... params);
+
void log(LogLevel logLevel, String message, Throwable throwable);
+
List<String> getMandatoryFields();
+
ILogger clear();
+
ILogger startTimer();
+
ILogger setKeyRequestId(String keyRequestId);
ILogger setKeyInvocationId(String keyInvocationId);
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java
index fce1143ad1..c0dee08fa7 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java
@@ -1,12 +1,17 @@
package org.openecomp.sdc.common.log.elements;
public class ErrorLogOptionalData {
+
private String targetEntity;
private String targetServiceName;
public ErrorLogOptionalData() {
}
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
String getTargetEntity() {
return targetEntity;
}
@@ -23,11 +28,8 @@ public class ErrorLogOptionalData {
this.targetServiceName = targetServiceName;
}
- public static Builder newBuilder() {
- return new Builder();
- }
-
public static class Builder {
+
private final ErrorLogOptionalData instance;
private Builder() {
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java
index 3deb115f4b..8aba0cb209 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java
@@ -1,497 +1,482 @@
package org.openecomp.sdc.common.log.elements;
+import static java.lang.Integer.valueOf;
+
+import java.net.InetAddress;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.openecomp.sdc.common.log.enums.ConstantsLogging;
import org.openecomp.sdc.common.log.api.ILogConfiguration;
import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.enums.ConstantsLogging;
import org.openecomp.sdc.common.log.enums.Severity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
-import javax.servlet.http.HttpServletRequest;
-import java.net.InetAddress;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
-
-import static java.lang.Integer.valueOf;
public class LogFieldsMdcHandler implements ILogFieldsHandler {
- private static LogFieldsMdcHandler instanceMdcWrapper = new LogFieldsMdcHandler();
-
- public static LogFieldsMdcHandler getInstance() {
- return instanceMdcWrapper;
- }
-
- private final static String dateFormatPattern = "yyyy-MM-dd'T'HH:mm:ss.SSSz";
- private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter
- .ofPattern(dateFormatPattern);
- protected static Logger log = LoggerFactory.getLogger(LogFieldsMdcHandler.class.getName());
- protected static String hostAddress;
- protected static String fqdn;
-
- static {
- try {
- hostAddress = InetAddress.getLocalHost().getHostAddress();
- fqdn = InetAddress.getByName(hostAddress).getCanonicalHostName();
- } catch (Exception ex) {
- log.error("failed to get machine parameters", ex);
- }
- }
-
- @Override
- public void startAuditTimer() {
- if (StringUtils.isEmpty(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP))) {
- MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, generatedTimeNow());
- }
- }
-
- @Override
- public void startMetricTimer() {
- if (StringUtils.isEmpty(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP))) {
- MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, generatedTimeNow());
- }
- }
-
- @Override
- public void stopAuditTimer() {
- //set start time if it is not set yet
- startAuditTimer();
- MDC.put(ILogConfiguration.MDC_END_TIMESTAMP, generatedTimeNow());
- setElapsedTime(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
- }
-
- @Override
- public void stopMetricTimer() {
- //set start time if it is not set yet
- startMetricTimer();
- MDC.put(ILogConfiguration.MDC_END_TIMESTAMP, generatedTimeNow());
- setElapsedTime(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP));
- }
-
- @Override
- public void setClassName(String className) {
- MDC.put(ILogConfiguration.MDC_CLASS_NAME, className);
- }
-
- @Override
- public void setServerFQDN(String serverFQDN) {
- MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
- }
-
- @Override
- public void setServerIPAddress(String serverIPAddress) {
- MDC.put(ILogConfiguration.MDC_SERVER_IP_ADDRESS, serverIPAddress);
- }
-
- @Override
- public void setServerFQDNInternally() {
- setServerFQDN(fqdn);
- }
-
- @Override
- public void setServerIPAddressInternally() {
- setServerIPAddress(hostAddress);
- }
-
- @Override
- public void setInstanceUUID(String instanceUUID) {
- MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, instanceUUID);
- }
-
- @Override
- public void setProcessKey(String processKey) {
- MDC.put(ILogConfiguration.MDC_PROCESS_KEY, processKey);
- }
-
- @Override
- public void setAlertSeverity(Severity alertSeverity) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_SEVERITY, String.valueOf(alertSeverity.getSeverityType()));
- }
-
- @Override
- public void setOptCustomField1(String customField1) {
- MDC.put(ILogConfiguration.MDC_OPT_FIELD1, customField1);
- }
-
- @Override
- public void setOutgoingInvocationId(String outgoingInvocationId) {
- MDC.put(ILogConfiguration.MDC_OUTGOING_INVOCATION_ID, outgoingInvocationId);
- }
-
- @Override
- public void setKeyRequestId(String keyRequestId) {
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID,
- keyRequestId); // eg. servletRequest.getSession().getId()
- }
-
- @Override
- public void setKeyInvocationId(String invocationId ) {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID,
- invocationId);
- }
-
- @Override
- public void setRemoteHost(String remoteHost) {
- MDC.put(ILogConfiguration.MDC_REMOTE_HOST, remoteHost);
- }
-
- @Override
- public void setServiceName(String serviceName) {
- MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
- }
-
- @Override
- public void setStatusCode(String statusCode) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
- }
-
- @Override
- public void setPartnerName(String partnerName) {
- MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
- }
-
- @Override
- public void setResponseCode(int responseCode) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, Integer.toString(responseCode));
- }
-
- @Override
- public void setResponseDesc(String responseDesc) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, responseDesc);
- }
-
- @Override
- public void setServiceInstanceId(String serviceInstanceId) {
- MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, serviceInstanceId);
- }
-
- @Override
- public void setTargetEntity(String targetEntity) {
- MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
- }
-
- @Override
- public void setTargetServiceName(String targetServiceName) {
- MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, targetServiceName);
- }
-
- @Override
- public void setTargetVirtualEntity(String targetVirtualEntity) {
- MDC.put(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY, targetVirtualEntity);
- }
-
- @Override
- public void setErrorCode(int errorCode) {
- MDC.put(ILogConfiguration.MDC_ERROR_CODE, valueOf(errorCode).toString());
- }
-
- @Override
- public void setErrorCategory(String errorCategory) {
- MDC.put(ILogConfiguration.MDC_ERROR_CATEGORY, errorCategory);
- }
-
- @Override
- public String getErrorCode() {
- return MDC.get(ILogConfiguration.MDC_ERROR_CODE);
- }
-
- @Override
- public String getServiceName() {
- return MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME);
- }
-
- @Override
- public String getErrorCategory() {
- return MDC.get(ILogConfiguration.MDC_ERROR_CATEGORY);
- }
-
- @Override
- public void clear() {
- MDC.clear();
- }
-
- @Override
- public boolean isMDCParamEmpty(String mdcKeyName) {
- return StringUtils.isEmpty(MDC.get(mdcKeyName));
- }
-
- @Override
- public String getFqdn() {
- return fqdn;
- }
-
- @Override
- public String getHostAddress() {
- return hostAddress;
- }
-
- @Override
- public String getKeyRequestId() {
- return MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
- }
-
- @Override
- public String getTargetEntity() {
- return MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY);
- }
-
- @Override
- public String getTargetServiceName() {
- return MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
- }
-
- @Override
- public void removeStatusCode() {
- MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
- }
-
- @Override
- public void removePartnerName() {
- MDC.remove(ONAPLogConstants.MDCs.PARTNER_NAME);
- }
-
- @Override
- public void removeResponseCode() {
- MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
- }
-
- @Override
- public void removeResponseDesc() {
- MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
- }
-
- @Override
- public void removeServiceInstanceId() {
- MDC.remove(ILogConfiguration.MDC_SERVICE_INSTANCE_ID);
- }
-
- @Override
- public void removeTargetEntity() {
- MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY);
- }
-
- @Override
- public void removeTargetServiceName() {
- MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
- }
-
- @Override
- public void removeTargetVirtualEntity() {
- MDC.remove(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY);
- }
-
- @Override
- public void removeErrorCode() {
- MDC.remove(ILogConfiguration.MDC_ERROR_CODE);
- }
-
- @Override
- public void removeErrorCategory() {
- MDC.remove(ILogConfiguration.MDC_ERROR_CATEGORY);
- }
-
- @Override
- public void removeErrorDescription() {
- MDC.remove(ILogConfiguration.MDC_ERROR_DESC);
- }
-
- @Override
- public void setAuditMessage(String message) {
- MDC.put(ILogConfiguration.MDC_AUDIT_MESSAGE, message);
- }
-
- @Override
- public String getAuditMessage() {
- return MDC.get(ILogConfiguration.MDC_AUDIT_MESSAGE);
- }
-
-
- @Override
- public String getSupportablityStatusCode() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE);
- }
-
- @Override
- public String getSupportablityAction() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_ACTION);
-
- }
-
-
- @Override
- public String getRemoteHost() {
- return MDC.get(ILogConfiguration.MDC_REMOTE_HOST);
- }
-
- @Override
- public String getServerIpAddress() {
- return MDC.get(ILogConfiguration.MDC_SERVER_IP_ADDRESS);
- }
+ private final static String dateFormatPattern = "yyyy-MM-dd'T'HH:mm:ss.SSSz";
+ protected static Logger log = LoggerFactory.getLogger(LogFieldsMdcHandler.class.getName());
+ protected static String hostAddress;
+ protected static String fqdn;
+ private static LogFieldsMdcHandler instanceMdcWrapper = new LogFieldsMdcHandler();
+
+ static {
+ try {
+ hostAddress = InetAddress.getLocalHost().getHostAddress();
+ fqdn = InetAddress.getByName(hostAddress).getCanonicalHostName();
+ } catch (Exception ex) {
+ log.error("failed to get machine parameters", ex);
+ }
+ }
+
+ private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormatPattern);
+
+ public static LogFieldsMdcHandler getInstance() {
+ return instanceMdcWrapper;
+ }
+
+ @Override
+ public void startAuditTimer() {
+ if (StringUtils.isEmpty(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP))) {
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, generatedTimeNow());
+ }
+ }
+
+ @Override
+ public void startMetricTimer() {
+ if (StringUtils.isEmpty(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP))) {
+ MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, generatedTimeNow());
+ }
+ }
+
+ @Override
+ public void stopAuditTimer() {
+ //set start time if it is not set yet
+ startAuditTimer();
+ MDC.put(ILogConfiguration.MDC_END_TIMESTAMP, generatedTimeNow());
+ setElapsedTime(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
+ }
+
+ @Override
+ public void stopMetricTimer() {
+ //set start time if it is not set yet
+ startMetricTimer();
+ MDC.put(ILogConfiguration.MDC_END_TIMESTAMP, generatedTimeNow());
+ setElapsedTime(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP));
+ }
+
+ @Override
+ public void setClassName(String className) {
+ MDC.put(ILogConfiguration.MDC_CLASS_NAME, className);
+ }
+
+ @Override
+ public void setServerFQDN(String serverFQDN) {
+ MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
+ }
+
+ @Override
+ public void setServerIPAddress(String serverIPAddress) {
+ MDC.put(ILogConfiguration.MDC_SERVER_IP_ADDRESS, serverIPAddress);
+ }
+
+ @Override
+ public void setServerFQDNInternally() {
+ setServerFQDN(fqdn);
+ }
+
+ @Override
+ public void setServerIPAddressInternally() {
+ setServerIPAddress(hostAddress);
+ }
+
+ @Override
+ public void setInstanceUUID(String instanceUUID) {
+ MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, instanceUUID);
+ }
+
+ @Override
+ public void setProcessKey(String processKey) {
+ MDC.put(ILogConfiguration.MDC_PROCESS_KEY, processKey);
+ }
+
+ @Override
+ public void setAlertSeverity(Severity alertSeverity) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_SEVERITY, String.valueOf(alertSeverity.getSeverityType()));
+ }
+
+ @Override
+ public void setOptCustomField1(String customField1) {
+ MDC.put(ILogConfiguration.MDC_OPT_FIELD1, customField1);
+ }
+
+ @Override
+ public void setOutgoingInvocationId(String outgoingInvocationId) {
+ MDC.put(ILogConfiguration.MDC_OUTGOING_INVOCATION_ID, outgoingInvocationId);
+ }
+
+ @Override
+ public void setStatusCode(String statusCode) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
+ }
+
+ @Override
+ public void setResponseCode(int responseCode) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, Integer.toString(responseCode));
+ }
+
+ @Override
+ public void setResponseDesc(String responseDesc) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, responseDesc);
+ }
+
+ @Override
+ public void setServiceInstanceId(String serviceInstanceId) {
+ MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, serviceInstanceId);
+ }
+
+ @Override
+ public void setTargetVirtualEntity(String targetVirtualEntity) {
+ MDC.put(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY, targetVirtualEntity);
+ }
+
+ @Override
+ public String getErrorCode() {
+ return MDC.get(ILogConfiguration.MDC_ERROR_CODE);
+ }
+
+ @Override
+ public void setErrorCode(int errorCode) {
+ MDC.put(ILogConfiguration.MDC_ERROR_CODE, valueOf(errorCode).toString());
+ }
+
+ @Override
+ public String getServiceName() {
+ return MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME);
+ }
+
+ @Override
+ public void setServiceName(String serviceName) {
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
+ }
+
+ @Override
+ public String getErrorCategory() {
+ return MDC.get(ILogConfiguration.MDC_ERROR_CATEGORY);
+ }
+
+ @Override
+ public void setErrorCategory(String errorCategory) {
+ MDC.put(ILogConfiguration.MDC_ERROR_CATEGORY, errorCategory);
+ }
+
+ @Override
+ public void clear() {
+ MDC.clear();
+ }
+
+ @Override
+ public boolean isMDCParamEmpty(String mdcKeyName) {
+ return StringUtils.isEmpty(MDC.get(mdcKeyName));
+ }
+
+ @Override
+ public String getFqdn() {
+ return fqdn;
+ }
+
+ @Override
+ public String getHostAddress() {
+ return hostAddress;
+ }
+
+ @Override
+ public String getKeyRequestId() {
+ return MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+ }
+
+ @Override
+ public void setKeyRequestId(String keyRequestId) {
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID,
+ keyRequestId); // eg. servletRequest.getSession().getId()
+ }
+
+ @Override
+ public String getTargetEntity() {
+ return MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY);
+ }
+
+ @Override
+ public void setTargetEntity(String targetEntity) {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
+ }
+
+ @Override
+ public String getTargetServiceName() {
+ return MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
+ }
+
+ @Override
+ public void setTargetServiceName(String targetServiceName) {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, targetServiceName);
+ }
+
+ @Override
+ public void removeStatusCode() {
+ MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
+ }
+
+ @Override
+ public void removePartnerName() {
+ MDC.remove(ONAPLogConstants.MDCs.PARTNER_NAME);
+ }
+
+ @Override
+ public void removeResponseCode() {
+ MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
+ }
+
+ @Override
+ public void removeResponseDesc() {
+ MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
+ }
+
+ @Override
+ public void removeServiceInstanceId() {
+ MDC.remove(ILogConfiguration.MDC_SERVICE_INSTANCE_ID);
+ }
+
+ @Override
+ public void removeTargetEntity() {
+ MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY);
+ }
+
+ @Override
+ public void removeTargetServiceName() {
+ MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
+ }
+
+ @Override
+ public void removeTargetVirtualEntity() {
+ MDC.remove(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY);
+ }
+
+ @Override
+ public void removeErrorCode() {
+ MDC.remove(ILogConfiguration.MDC_ERROR_CODE);
+ }
+
+ @Override
+ public void removeErrorCategory() {
+ MDC.remove(ILogConfiguration.MDC_ERROR_CATEGORY);
+ }
+
+ @Override
+ public void removeErrorDescription() {
+ MDC.remove(ILogConfiguration.MDC_ERROR_DESC);
+ }
+
+ @Override
+ public String getAuditMessage() {
+ return MDC.get(ILogConfiguration.MDC_AUDIT_MESSAGE);
+ }
+
+ @Override
+ public void setAuditMessage(String message) {
+ MDC.put(ILogConfiguration.MDC_AUDIT_MESSAGE, message);
+ }
+
+ @Override
+ public String getSupportablityStatusCode() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE);
+ }
+
+ @Override
+ public void setSupportablityStatusCode(String statusCode) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE, statusCode);
+ }
+
+ @Override
+ public String getSupportablityAction() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_ACTION);
+ }
+
+ @Override
+ public void setSupportablityAction(String action) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_ACTION, action);
+ }
+
+ @Override
+ public String getRemoteHost() {
+ return MDC.get(ILogConfiguration.MDC_REMOTE_HOST);
+ }
+
+ @Override
+ public void setRemoteHost(String remoteHost) {
+ MDC.put(ILogConfiguration.MDC_REMOTE_HOST, remoteHost);
+ }
+ @Override
+ public String getServerIpAddress() {
+ return MDC.get(ILogConfiguration.MDC_SERVER_IP_ADDRESS);
+ }
// @Override
+
// public String getSupportablityCsarName() {
+
// return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_NAME);
-// }
-
- @Override
- public String getSupportablityCsarUUID() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID);
- }
-
- @Override
- public String getSupportablityCsarVersion() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION);
-
- }
-
- @Override
- public String getSupportablityComponentName() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME);
- }
-
- @Override
- public String getSupportablityComponentUUID() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID);
-
- }
-
- @Override
- public String getSupportablityComponentVersion() {
- return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION);
- }
-
- @Override
- public String getKeyInvocationId() {
- return MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
- }
-
- @Override
- public void setSupportablityStatusCode(String statusCode) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE, statusCode);
- }
-
- @Override
- public void setSupportablityAction(String action) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_ACTION, action);
- }
-
- @Override
- public void setSupportablityCsarUUID(String uuid) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID, uuid);
- }
-
- @Override
- public void setSupportablityCsarVersion(String version) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION, version);
- }
-
- @Override
- public void setSupportablityComponentName(String name) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, name);
- }
-
- @Override
- public void setSupportablityComponentUUID(String uuid) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, uuid);
- }
-
- @Override
- public void setSupportablityComponentVersion(String version) {
- MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, version);
- }
-
- @Override
- public void removeSupportablityAction() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_ACTION);
- }
-
- @Override
- public void removeSupportablityComponentName() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME);
- }
-
- @Override
- public void removeSupportablityComponentUUID() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID);
- }
-
- @Override
- public void removeSupportablityComponentVersion() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION);
- }
-// @Override
-// public void removeSupportablityCsarName() {
-// MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_NAME);
-// }
+ // }
+ @Override
+ public String getSupportablityCsarUUID() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID);
+ }
+
+ @Override
+ public void setSupportablityCsarUUID(String uuid) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID, uuid);
+ }
+
+ @Override
+ public String getSupportablityCsarVersion() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION);
+ }
+
+ @Override
+ public void setSupportablityCsarVersion(String version) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION, version);
+ }
+
+ @Override
+ public String getSupportablityComponentName() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME);
+ }
+
+ @Override
+ public void setSupportablityComponentName(String name) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, name);
+ }
+
+ @Override
+ public String getSupportablityComponentUUID() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID);
+ }
+
+ @Override
+ public void setSupportablityComponentUUID(String uuid) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, uuid);
+ }
+
+ @Override
+ public String getSupportablityComponentVersion() {
+ return MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION);
+ }
- @Override
- public void removeSupportablityCsarUUID() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID);
- }
+ @Override
+ public void setSupportablityComponentVersion(String version) {
+ MDC.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, version);
+ }
- @Override
- public void removeSupportablityCsarVersion() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION);
- }
+ @Override
+ public String getKeyInvocationId() {
+ return MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
+ }
- @Override
- public void removeSupportablityStatusCode() {
- MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE);
- }
+ @Override
+ public void setKeyInvocationId(String invocationId) {
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ }
- @Override
- public String getPartnerName() {
- return MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
- }
+ @Override
+ public void removeSupportablityAction() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_ACTION);
+ }
- private void setElapsedTime(String beginTimestamp) {
- try {
- final LocalDateTime startTime = LocalDateTime.parse(beginTimestamp, dateTimeFormatter);
- final LocalDateTime endTime = LocalDateTime
- .parse(MDC.get(ILogConfiguration.MDC_END_TIMESTAMP), dateTimeFormatter);
- final Duration timeDifference = Duration.between(startTime, endTime);
+ @Override
+ public void removeSupportablityComponentName() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME);
+ }
- MDC.put(ILogConfiguration.MDC_ELAPSED_TIME, String.valueOf(timeDifference.toMillis()));
+ @Override
+ public void removeSupportablityComponentUUID() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID);
+ }
+
+ @Override
+ public void removeSupportablityComponentVersion() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION);
+ }
- } catch (Exception ex) {
- log.error("failed to calculate elapsed time", ex);
+ // }
+ @Override
+ public void removeSupportablityCsarUUID() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID);
}
- }
+// @Override
+
+// public void removeSupportablityCsarName() {
- private String generatedTimeNow() {
- return dateTimeFormatter
- .withZone(ZoneOffset.UTC)
- .format(Instant.now());
- }
+// MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_NAME);
- public void collectRequestInfoForErrorAndDebugLogging(HttpServletRequest httpRequest) {
- LogFieldsMdcHandler.getInstance().clear();
- String partnerName = LoggerBase.getPartnerName(httpRequest);
- LogFieldsMdcHandler.getInstance().setPartnerName(partnerName);
+ @Override
+ public void removeSupportablityCsarVersion() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION);
+ }
- String serviceInstanceID = httpRequest.getHeader(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER);
- LogFieldsMdcHandler.getInstance().setServiceInstanceId(serviceInstanceID);
+ @Override
+ public void removeSupportablityStatusCode() {
+ MDC.remove(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE);
+ }
- LogFieldsMdcHandler.getInstance().setRemoteHost(httpRequest.getRemoteHost());
- LogFieldsMdcHandler.getInstance().setServerIPAddress(httpRequest.getLocalAddr());
+ @Override
+ public String getPartnerName() {
+ return MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
+ }
- String requestId = LoggerBase.getRequestId(httpRequest);
- LogFieldsMdcHandler.getInstance().setKeyRequestId(requestId);
+ @Override
+ public void setPartnerName(String partnerName) {
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
+ }
- LogFieldsMdcHandler.getInstance().setServiceName(httpRequest.getRequestURI());
- }
+ private void setElapsedTime(String beginTimestamp) {
+ try {
+ final LocalDateTime startTime = LocalDateTime.parse(beginTimestamp, dateTimeFormatter);
+ final LocalDateTime endTime = LocalDateTime.parse(MDC.get(ILogConfiguration.MDC_END_TIMESTAMP), dateTimeFormatter);
+ final Duration timeDifference = Duration.between(startTime, endTime);
+ MDC.put(ILogConfiguration.MDC_ELAPSED_TIME, String.valueOf(timeDifference.toMillis()));
+ } catch (Exception ex) {
+ log.error("failed to calculate elapsed time", ex);
+ }
+ }
- public void addInfoForErrorAndDebugLogging(String partnerName){
- LogFieldsMdcHandler.getInstance().clear();
- LogFieldsMdcHandler.getInstance().setPartnerName(partnerName);
+ private String generatedTimeNow() {
+ return dateTimeFormatter.withZone(ZoneOffset.UTC).format(Instant.now());
+ }
- String requestId = LoggerBase.generateKeyRequestId();
- LogFieldsMdcHandler.getInstance().setKeyRequestId(requestId);
- }
+ public void collectRequestInfoForErrorAndDebugLogging(HttpServletRequest httpRequest) {
+ LogFieldsMdcHandler.getInstance().clear();
+ String partnerName = LoggerBase.getPartnerName(httpRequest);
+ LogFieldsMdcHandler.getInstance().setPartnerName(partnerName);
+ String serviceInstanceID = httpRequest.getHeader(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER);
+ LogFieldsMdcHandler.getInstance().setServiceInstanceId(serviceInstanceID);
+ LogFieldsMdcHandler.getInstance().setRemoteHost(httpRequest.getRemoteHost());
+ LogFieldsMdcHandler.getInstance().setServerIPAddress(httpRequest.getLocalAddr());
+ String requestId = LoggerBase.getRequestId(httpRequest);
+ LogFieldsMdcHandler.getInstance().setKeyRequestId(requestId);
+ LogFieldsMdcHandler.getInstance().setServiceName(httpRequest.getRequestURI());
+ }
+
+ public void addInfoForErrorAndDebugLogging(String partnerName) {
+ LogFieldsMdcHandler.getInstance().clear();
+ LogFieldsMdcHandler.getInstance().setPartnerName(partnerName);
+ String requestId = LoggerBase.generateKeyRequestId();
+ LogFieldsMdcHandler.getInstance().setKeyRequestId(requestId);
+ }
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java
index 771ecfd9d4..97a0120773 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java
@@ -1,6 +1,9 @@
package org.openecomp.sdc.common.log.elements;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.common.log.api.ILogConfiguration;
import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
@@ -10,40 +13,36 @@ import org.slf4j.Logger;
import org.slf4j.MDC;
import org.slf4j.MarkerFactory;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
public class LoggerAudit extends LoggerBase {
+
private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
- ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
- ILogConfiguration.MDC_END_TIMESTAMP,
- ONAPLogConstants.MDCs.REQUEST_ID,
- ONAPLogConstants.MDCs.SERVICE_NAME,
- ONAPLogConstants.MDCs.PARTNER_NAME,
- ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE,
- ONAPLogConstants.MDCs.RESPONSE_CODE,
- ILogConfiguration.MDC_SERVICE_INSTANCE_ID,
- ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION,
- ILogConfiguration.MDC_ELAPSED_TIME,
- ILogConfiguration.MDC_SERVER_IP_ADDRESS,
- ONAPLogConstants.MDCs.SERVER_FQDN));
+ ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
+ ILogConfiguration.MDC_END_TIMESTAMP,
+ ONAPLogConstants.MDCs.REQUEST_ID,
+ ONAPLogConstants.MDCs.SERVICE_NAME,
+ ONAPLogConstants.MDCs.PARTNER_NAME,
+ ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE,
+ ONAPLogConstants.MDCs.RESPONSE_CODE,
+ ILogConfiguration.MDC_SERVICE_INSTANCE_ID,
+ ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION,
+ ILogConfiguration.MDC_ELAPSED_TIME,
+ ILogConfiguration.MDC_SERVER_IP_ADDRESS,
+ ONAPLogConstants.MDCs.SERVER_FQDN));
private static ArrayList<String> optionalFields = new ArrayList<>(Arrays.asList(
- ONAPLogConstants.MDCs.INSTANCE_UUID,
- ONAPLogConstants.MDCs.RESPONSE_SEVERITY,
- ILogConfiguration.MDC_REMOTE_HOST,
- ILogConfiguration.MDC_CLASS_NAME,
- ILogConfiguration.MDC_PROCESS_KEY,
- ILogConfiguration.MDC_OPT_FIELD1,
- ILogConfiguration.MDC_OPT_FIELD2,
- ILogConfiguration.MDC_OPT_FIELD3,
- ILogConfiguration.MDC_OPT_FIELD4));
+ ONAPLogConstants.MDCs.INSTANCE_UUID,
+ ONAPLogConstants.MDCs.RESPONSE_SEVERITY,
+ ILogConfiguration.MDC_REMOTE_HOST,
+ ILogConfiguration.MDC_CLASS_NAME,
+ ILogConfiguration.MDC_PROCESS_KEY,
+ ILogConfiguration.MDC_OPT_FIELD1,
+ ILogConfiguration.MDC_OPT_FIELD2,
+ ILogConfiguration.MDC_OPT_FIELD3,
+ ILogConfiguration.MDC_OPT_FIELD4));
LoggerAudit(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
//TODO Andrey, set default marker
- super (ecompMdcWrapper, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), logger);
+ super(ecompMdcWrapper, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), logger);
//put the remote host and FQDN values from another thread if they are set
ecompMdcWrapper.setServerIPAddressInternally();
ecompMdcWrapper.setServerFQDNInternally();
@@ -102,7 +101,8 @@ public class LoggerAudit extends LoggerBase {
}
public LoggerAudit setStatusCodeByResponseCode(String responseCode) {
- String respStatus = Integer.parseInt(responseCode) / 100 == 2 ? ONAPLogConstants.ResponseStatus.COMPLETE.name() : ONAPLogConstants.ResponseStatus.ERROR.name();
+ String respStatus = Integer.parseInt(responseCode) / 100 == 2 ? ONAPLogConstants.ResponseStatus.COMPLETE.name()
+ : ONAPLogConstants.ResponseStatus.ERROR.name();
ecompLogFieldsHandler.setStatusCode(respStatus);
return this;
}
@@ -112,7 +112,6 @@ public class LoggerAudit extends LoggerBase {
return this;
}
-
public LoggerAudit setPartnerName(String partnerName) {
ecompLogFieldsHandler.setPartnerName(partnerName);
return this;
@@ -137,7 +136,6 @@ public class LoggerAudit extends LoggerBase {
return ecompLogFieldsHandler.getAuditMessage();
}
-
@Override
public List<String> getMandatoryFields() {
return Collections.unmodifiableList(mandatoryFields);
@@ -150,5 +148,4 @@ public class LoggerAudit extends LoggerBase {
ecompLogFieldsHandler.setServerIPAddressInternally();
return this;
}
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java
index 5295c4ab58..a409995244 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java
@@ -38,10 +38,9 @@ import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
-
/**
- * Created by mm288v on 12/27/2017. This class holds the common behavior of all Loger-Typed classes. The Concrete
- * loggers shoudl derive from this one.
+ * Created by mm288v on 12/27/2017. This class holds the common behavior of all Loger-Typed classes. The Concrete loggers shoudl derive from this
+ * one.
*/
public abstract class LoggerBase implements ILogger {
@@ -66,16 +65,16 @@ public abstract class LoggerBase implements ILogger {
String requestId = httpRequest.getHeader(ConstantsLogging.X_REQUEST_ID);
String transactionReId = httpRequest.getHeader(ConstantsLogging.X_TRANSACTION_ID_HEADER);
String ecompRequestId = httpRequest.getHeader(ConstantsLogging.X_ECOMP_REQUEST_ID_HEADER);
- return Arrays.asList(onapRequestId, requestId, transactionReId, ecompRequestId).stream()
- .filter(id -> !StringUtils.isEmpty(id)).findFirst().orElse(generateKeyRequestId());
+ return Arrays.asList(onapRequestId, requestId, transactionReId, ecompRequestId).stream().filter(id -> !StringUtils.isEmpty(id)).findFirst()
+ .orElse(generateKeyRequestId());
}
public static String getPartnerName(HttpServletRequest httpRequest) {
String userId = httpRequest.getHeader(ConstantsLogging.USER_ID_HEADER);
String onapPartnerName = httpRequest.getHeader(ONAPLogConstants.Headers.PARTNER_NAME);
String reqUri = httpRequest.getHeader(ConstantsLogging.USER_AGENT_HEADER);
- return Arrays.asList(userId, onapPartnerName, reqUri).stream()
- .filter(pn -> !StringUtils.isEmpty(pn)).findFirst().orElse(ConstantsLogging.PartnerName_Unknown);
+ return Arrays.asList(userId, onapPartnerName, reqUri).stream().filter(pn -> !StringUtils.isEmpty(pn)).findFirst()
+ .orElse(ConstantsLogging.PartnerName_Unknown);
}
protected void setKeyRequestIdIfNotSetYet() {
@@ -87,7 +86,6 @@ public abstract class LoggerBase implements ILogger {
private void validateMandatoryFields(String originMsg) {
// this method only checks if the mandatory fields have been initialized
String filedNameThatHasNotBeenInitialized = checkMandatoryFieldsExistInMDC();
-
if (myLogger.isDebugEnabled() && !"".equalsIgnoreCase(filedNameThatHasNotBeenInitialized)) {
myLogger.debug(MarkerFactory.getMarker(LogMarkers.DEBUG_MARKER.getText()),
String.format(missingLogFieldsMsg, filedNameThatHasNotBeenInitialized, originMsg));
@@ -127,7 +125,6 @@ public abstract class LoggerBase implements ILogger {
@Override
public void log(LogLevel logLevel, String message, Object... params) {
validateMandatoryFields(message);
-
switch (logLevel) {
case ERROR:
case FATAL: //TODO check how to log "FATAL" word
@@ -153,7 +150,6 @@ public abstract class LoggerBase implements ILogger {
@Override
public void log(LogLevel logLevel, String message, Throwable throwable) {
validateMandatoryFields(message);
-
switch (logLevel) {
case ERROR:
case FATAL: //TODO check how to log "FATAL" word
@@ -179,7 +175,6 @@ public abstract class LoggerBase implements ILogger {
@Override
public void log(Marker marker, LogLevel logLevel, String message, Object... params) {
validateMandatoryFields(message);
-
switch (logLevel) {
case ERROR:
case FATAL: //TODO check how to log "FATAL" word
@@ -206,7 +201,6 @@ public abstract class LoggerBase implements ILogger {
return String.format("%s: %s", message, throwable.getLocalizedMessage());
}
-
@Override
public ILogger clear() {
ecompLogFieldsHandler.clear();
@@ -219,12 +213,9 @@ public abstract class LoggerBase implements ILogger {
return this;
}
-
@Override
public ILogger setKeyInvocationId(String keyInvocationId) {
ecompLogFieldsHandler.setKeyInvocationId(keyInvocationId);
return this;
}
-
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java
index 347a60f9ea..7db91244c6 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java
@@ -72,61 +72,42 @@ public class LoggerError extends LoggerBase {
return this;
}
- public void log(LogLevel logLevel,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String targetEntity,
- String message, Object... params) {
+ public void log(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity, String message,
+ Object... params) {
fillFieldsBeforeLogging(logLevel, errorCodeEnum, serviceName, targetEntity, null);
super.log(logLevel, message, params);
}
- public void log(LogLevel logLevel,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- ErrorLogOptionalData errorLogOptionalData,
- String description,
- Object... params) {
- fillFieldsBeforeLogging(logLevel, errorCodeEnum, serviceName,
- errorLogOptionalData.getTargetEntity(), errorLogOptionalData.getTargetServiceName());
+ public void log(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, ErrorLogOptionalData errorLogOptionalData,
+ String description, Object... params) {
+ fillFieldsBeforeLogging(logLevel, errorCodeEnum, serviceName, errorLogOptionalData.getTargetEntity(),
+ errorLogOptionalData.getTargetServiceName());
super.log(logLevel, description, params);
}
- private void fillFieldsBeforeLogging(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName,
- String targetEntity, String targetServiceName) {
+ private void fillFieldsBeforeLogging(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity,
+ String targetServiceName) {
clear();
ecompLogFieldsHandler.setErrorCode(errorCodeEnum.getErrorCode());
ecompLogFieldsHandler.setErrorCategory(logLevel.name());
-
ecompLogFieldsHandler.setTargetEntity(targetEntity);
ecompLogFieldsHandler.setTargetServiceName(targetServiceName);
-
if (StringUtils.isEmpty(ecompLogFieldsHandler.getServiceName())) {
ecompLogFieldsHandler.setServiceName(serviceName);
}
-
setKeyRequestIdIfNotSetYet();
}
- public void log(EcompErrorSeverity errorSeverity,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String targetEntity,
- String message, Object... params) {
+ public void log(EcompErrorSeverity errorSeverity, EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity, String message,
+ Object... params) {
log(convertFromSeverityErrorLevel(errorSeverity), errorCodeEnum, serviceName, targetEntity, message, params);
}
- public void log(LogLevel logLevel,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String message, Object... params) {
+ public void log(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, String message, Object... params) {
log(logLevel, errorCodeEnum, serviceName, (String) null, message, params);
}
- public void log(LogLevel logLevel,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String message) {
+ public void log(LogLevel logLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, String message) {
log(logLevel, errorCodeEnum, serviceName, message);
}
@@ -160,5 +141,4 @@ public class LoggerError extends LoggerBase {
}
return LogLevel.ERROR;
}
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java
index fb97ebddee..519bea0f6d 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java
@@ -3,9 +3,7 @@ package org.openecomp.sdc.common.log.elements;
import org.slf4j.Logger;
/**
- * Created by dd4296 on 12/26/2017.
- * this factory helps decouple the classes for Stopwatch and LogFieldsMdcHandler from
- * the EcompLogger classes
+ * Created by dd4296 on 12/26/2017. this factory helps decouple the classes for Stopwatch and LogFieldsMdcHandler from the EcompLogger classes
*/
public class LoggerFactory {
@@ -14,49 +12,38 @@ public class LoggerFactory {
@SuppressWarnings("unchecked")
public static <T, V> V getLogger(Class<T> type, Logger logger) {
-
if (type.isAssignableFrom(LoggerAudit.class)) {
return (V) new LoggerAudit(new LogFieldsMdcHandler(), logger);
}
-
if (type.isAssignableFrom(LoggerDebug.class)) {
return (V) new LoggerDebug(new LogFieldsMdcHandler(), logger);
}
-
if (type.isAssignableFrom(LoggerMetric.class)) {
return (V) new LoggerMetric(new LogFieldsMdcHandler(), logger);
}
-
if (type.isAssignableFrom(LoggerError.class)) {
return (V) new LoggerError(new LogFieldsMdcHandler(), logger);
}
-
return null;
}
@SuppressWarnings("unchecked")
public static <T, V> V getMdcLogger(Class<T> type, Logger logger) {
-
if (type.isAssignableFrom(LoggerAudit.class)) {
return (V) new LoggerAudit(LogFieldsMdcHandler.getInstance(), logger);
}
-
if (type.isAssignableFrom(LoggerDebug.class)) {
return (V) new LoggerDebug(LogFieldsMdcHandler.getInstance(), logger);
}
-
if (type.isAssignableFrom(LoggerMetric.class)) {
return (V) new LoggerMetric(LogFieldsMdcHandler.getInstance(), logger);
}
-
if (type.isAssignableFrom(LoggerError.class)) {
return (V) new LoggerError(LogFieldsMdcHandler.getInstance(), logger);
}
-
if (type.isAssignableFrom(LoggerSupportability.class)) {
return (V) new LoggerSupportability(LogFieldsMdcHandler.getInstance(), logger);
}
-
return null;
}
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java
index c23861f1ff..4e98431a4b 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java
@@ -56,7 +56,6 @@ import org.openecomp.sdc.common.log.enums.Severity;
import org.slf4j.Logger;
import org.slf4j.MarkerFactory;
-
public class LoggerMetric extends LoggerBase {
private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
@@ -96,11 +95,7 @@ public class LoggerMetric extends LoggerBase {
ecompMdcWrapper.setServerFQDNInternally();
}
- public void log(Response.StatusType statusInfo,
- String className,
- LogLevel logLevel,
- Severity securityLevel,
- String message) {
+ public void log(Response.StatusType statusInfo, String className, LogLevel logLevel, Severity securityLevel, String message) {
log(statusInfo, className, logLevel, securityLevel, message);
}
@@ -142,13 +137,11 @@ public class LoggerMetric extends LoggerBase {
return this;
}
-
public LoggerMetric setInstanceUUID(String instanceUUID) {
ecompLogFieldsHandler.setInstanceUUID(instanceUUID);
return this;
}
-
public LoggerMetric setOutgoingInvocationId(String out_invocationId) {
ecompLogFieldsHandler.setOutgoingInvocationId(out_invocationId);
return this;
@@ -208,6 +201,4 @@ public class LoggerMetric extends LoggerBase {
ecompLogFieldsHandler.setTargetVirtualEntity(targetVirtualEntity);
return this;
}
-
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java
index cb22394463..d5bf374b47 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java
@@ -47,8 +47,7 @@ public class LoggerSupportability extends LoggerBase {
ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE));
public LoggerSupportability(ILogFieldsHandler ecompLogFieldsHandler, Logger logger) {
- super(ecompLogFieldsHandler, MarkerFactory.getMarker(LogMarkers.SUPPORTABILITY_MARKER.getText()),
- logger);
+ super(ecompLogFieldsHandler, MarkerFactory.getMarker(LogMarkers.SUPPORTABILITY_MARKER.getText()), logger);
}
public static LoggerSupportability getLogger(Class<?> clazz) {
@@ -56,12 +55,11 @@ public class LoggerSupportability extends LoggerBase {
}
public static LoggerSupportability getLogger(String className) {
- return LoggerFactory.getMdcLogger(LoggerSupportability.class,
- org.slf4j.LoggerFactory.getLogger(className));
+ return LoggerFactory.getMdcLogger(LoggerSupportability.class, org.slf4j.LoggerFactory.getLogger(className));
}
- public void log(LoggerSupportabilityActions action, Map<String, String> componentMetaData, StatusCode statusCode,
- String message, Object... params) {
+ public void log(LoggerSupportabilityActions action, Map<String, String> componentMetaData, StatusCode statusCode, String message,
+ Object... params) {
fillFieldsBeforeLogging(action, componentMetaData, statusCode);
super.log(LogLevel.INFO, message, params);
}
@@ -70,20 +68,14 @@ public class LoggerSupportability extends LoggerBase {
log(action, null, statusCode, message, params);
}
- private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String, String> componentMetaData,
- StatusCode statusCode) {
+ private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String, String> componentMetaData, StatusCode statusCode) {
clear();
if (componentMetaData != null) {
- ecompLogFieldsHandler
- .setSupportablityCsarUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID));
- ecompLogFieldsHandler
- .setSupportablityCsarVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION));
- ecompLogFieldsHandler.setSupportablityComponentName(
- componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME));
- ecompLogFieldsHandler.setSupportablityComponentUUID(
- componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID));
- ecompLogFieldsHandler.setSupportablityComponentVersion(
- componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION));
+ ecompLogFieldsHandler.setSupportablityCsarUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID));
+ ecompLogFieldsHandler.setSupportablityCsarVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION));
+ ecompLogFieldsHandler.setSupportablityComponentName(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME));
+ ecompLogFieldsHandler.setSupportablityComponentUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID));
+ ecompLogFieldsHandler.setSupportablityComponentVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION));
}
ecompLogFieldsHandler.setSupportablityAction(action.getName());
ecompLogFieldsHandler.setSupportablityStatusCode(statusCode.getStatusCode());
@@ -101,7 +93,6 @@ public class LoggerSupportability extends LoggerBase {
return this;
}
-
@Override
public List<String> getMandatoryFields() {
return Collections.unmodifiableList(mandatoryFields);
@@ -111,5 +102,4 @@ public class LoggerSupportability extends LoggerBase {
public LoggerSupportability startTimer() {
return this;
}
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java
index 025de545a0..de1041b5c7 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.common.log.enums;
public final class ConstantsLogging {
+
public static final String USER_ID_HEADER = "USER_ID";
public static final String USER_AGENT_HEADER = "User-Agent";
public static final String PartnerName_Unknown = "UNKNOWN";
@@ -9,5 +10,4 @@ public final class ConstantsLogging {
public static final String X_REQUEST_ID = "X-RequestID";
public static final String X_ECOMP_INSTANCE_ID_HEADER = "X-ECOMP-InstanceID";
public static final String X_ECOMP_SERVICE_ID_HEADER = "X-ECOMP-ServiceID";
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java
index e88a074f0a..146c31c05e 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java
@@ -1,5 +1,3 @@
package org.openecomp.sdc.common.log.enums;
-public enum EcompErrorSeverity {
- INFO, WARN, ERROR, FATAL;
-}
+public enum EcompErrorSeverity {INFO, WARN, ERROR, FATAL;}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java
index 736194de18..a2e51e9848 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java
@@ -19,7 +19,6 @@
* Modifications copyright (c) 2020 Nordix Foundation
* ================================================================================
*/
-
package org.openecomp.sdc.common.log.enums;
import java.util.Arrays;
@@ -45,8 +44,7 @@ public enum EcompLoggerErrorCode {
public static EcompLoggerErrorCode getByValue(String ecompErrorCode) {
String errorPrefix = parseCode(ecompErrorCode);
- Optional<EcompLoggerErrorCode> optionalCode = Arrays.stream(values()).filter(v -> isCode(v, errorPrefix))
- .findFirst();
+ Optional<EcompLoggerErrorCode> optionalCode = Arrays.stream(values()).filter(v -> isCode(v, errorPrefix)).findFirst();
return optionalCode.orElse(UNKNOWN_ERROR);
}
@@ -61,5 +59,4 @@ public enum EcompLoggerErrorCode {
return UNKNOWN_ERROR.name();
}
}
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java
index 5b1ec9d4a9..9e4f495f91 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,18 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.common.log.enums;
/**
* Created by dd4296 on 12/14/2017.
*/
-public enum LogLevel {
- INFO,
- WARN,
- DEBUG,
- TRACE,
- ERROR,
- FATAL
-}
-
+public enum LogLevel {INFO, WARN, DEBUG, TRACE, ERROR, FATAL}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java
index fc7dca29fd..a884deb7c2 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java
@@ -30,11 +30,6 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum LogMarkers {
- DEBUG_MARKER("DEBUG_MARKER"),
- ERROR_MARKER("ERROR_MARKER"),
- METRIC_MARKER("METRICS"),
- SUPPORTABILITY_MARKER("SUPPORTABILITY_MARKER");
-
+ DEBUG_MARKER("DEBUG_MARKER"), ERROR_MARKER("ERROR_MARKER"), METRIC_MARKER("METRICS"), SUPPORTABILITY_MARKER("SUPPORTABILITY_MARKER");
private final String text;
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java
index 4f61b63a54..88b6dbfb6a 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java
@@ -27,6 +27,7 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum LoggerSupportabilityActions {
+ // @formatter:off
IMPORT_CSAR("CREATE RESOURCE FROM CSAR"),
CREATE_RESOURCE_FROM_YAML("CREATE RESOURCE FROM YAML"),
CREATE_RI_AND_RELATIONS("CREATE RI AND RELATIONS"),
@@ -80,6 +81,7 @@ public enum LoggerSupportabilityActions {
UPDATE_INSTANCE_REQUIREMENT("UPDATE INSTANCE REQUIREMENT"),
UPDATE_POLICY_TARGET("UPDATE POLICY TARGET"),
UPDATE_POLICIES_PROPERTIES("UPDATE POLICIES PROPERTIES");
+ // @formatter:on
private final String name;
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java
index 78fe9761cf..b4c11c7319 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java
@@ -19,7 +19,6 @@
* Modifications copyright (c) 2020 Nordix Foundation
* ================================================================================
*/
-
package org.openecomp.sdc.common.log.enums;
import lombok.AllArgsConstructor;
@@ -31,12 +30,6 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum Severity {
- OK(0),
- WARNING(1),
- CRITICAL(2),
- DOWN(3),
- UNREACHABLE(4);
-
+ OK(0), WARNING(1), CRITICAL(2), DOWN(3), UNREACHABLE(4);
private final int severityType;
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java
index ba9497eb5d..530b5b9cc4 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java
@@ -27,11 +27,6 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum StatusCode {
- ERROR("ERROR"),
- STARTED("STARTED"),
- COMPLETE("COMPLETE"),
- INPROGRESS("INPROGRESS");
-
+ ERROR("ERROR"), STARTED("STARTED"), COMPLETE("COMPLETE"), INPROGRESS("INPROGRESS");
private final String statusCode;
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java
index 1eaecca83b..477c114ebd 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java
@@ -21,7 +21,6 @@
*/
package org.openecomp.sdc.common.log.utils;
-
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -30,7 +29,5 @@ import lombok.Getter;
public enum EcompLogErrorCode {
E_399("Internal Invalid Object. Description: %s"),
E_210("Connection problem towards U-EB server. Reason: %s");
-
private final String description;
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java
index c621a2a975..d7adad0937 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,26 +17,21 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.common.log.utils;
-
public class LoggingThreadLocalsHolder {
- private static final ThreadLocal<String> uuidThreadLocal = new ThreadLocal<>();
-
- public static void setUuid(String uuid) {
- uuidThreadLocal.set(uuid);
- }
-
- public static String getUuid() {
- return uuidThreadLocal.get();
- }
-
+ private static final ThreadLocal<String> uuidThreadLocal = new ThreadLocal<>();
+ public static String getUuid() {
+ return uuidThreadLocal.get();
+ }
- public static void cleanup() {
- uuidThreadLocal.remove();
- }
+ public static void setUuid(String uuid) {
+ uuidThreadLocal.set(uuid);
+ }
+ public static void cleanup() {
+ uuidThreadLocal.remove();
+ }
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java
index 284104cd57..ae7dae4aa0 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java
@@ -1,22 +1,24 @@
package org.openecomp.sdc.common.log.wrappers;
import com.google.common.annotations.VisibleForTesting;
+import java.util.UUID;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.openecomp.sdc.common.log.elements.*;
+import org.openecomp.sdc.common.log.elements.ErrorLogOptionalData;
+import org.openecomp.sdc.common.log.elements.LoggerDebug;
+import org.openecomp.sdc.common.log.elements.LoggerError;
+import org.openecomp.sdc.common.log.elements.LoggerFactory;
+import org.openecomp.sdc.common.log.elements.LoggerMetric;
import org.openecomp.sdc.common.log.enums.EcompErrorSeverity;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.enums.LogLevel;
import org.slf4j.Marker;
-import java.util.UUID;
-
-
/**
- * This class wraps {@link org.slf4j.Logger} object and provides mandatory information required by Ecomp logging rules.
- * Note: All deprecated methods are supported to be compatible to the legacy code
- * and have not be used by the new code
+ * This class wraps {@link org.slf4j.Logger} object and provides mandatory information required by Ecomp logging rules. Note: All deprecated methods
+ * are supported to be compatible to the legacy code and have not be used by the new code
*/
public class Logger implements org.slf4j.Logger {
+
private final LoggerDebug debug;
private final LoggerError error;
private final LoggerMetric metric;
@@ -28,7 +30,6 @@ public class Logger implements org.slf4j.Logger {
this.debug = LoggerFactory.getMdcLogger(LoggerDebug.class, logger);
this.error = LoggerFactory.getMdcLogger(LoggerError.class, logger);
this.metric = LoggerFactory.getMdcLogger(LoggerMetric.class, logger);
-
}
private Logger(String className) {
@@ -43,7 +44,6 @@ public class Logger implements org.slf4j.Logger {
return new Logger(clazz.getName());
}
-
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@@ -57,12 +57,17 @@ public class Logger implements org.slf4j.Logger {
return logger.isTraceEnabled();
}
- public boolean isErrorEnabled() { return logger.isErrorEnabled(); }
+ public boolean isErrorEnabled() {
+ return logger.isErrorEnabled();
+ }
- public boolean isWarnEnabled() { return logger.isWarnEnabled(); }
+ public boolean isWarnEnabled() {
+ return logger.isWarnEnabled();
+ }
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(String msg) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg);
@@ -70,15 +75,17 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(String msg, Object o) {
-
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, o);
}
}
- public boolean isInfoEnabled() { return logger.isInfoEnabled(); }
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
@Override
public void info(String msg) {
@@ -108,29 +115,20 @@ public class Logger implements org.slf4j.Logger {
}
public void metric(String msg, Object... params) {
- metric.log(LogLevel.INFO, msg, params);
+ metric.log(LogLevel.INFO, msg, params);
}
public void invoke(String targetEntity, String targetServiceName, String serviceName, String msg, Object... params) {
-
String invocationId = UUID.randomUUID().toString();
String requestID = UUID.randomUUID().toString();
-
- metric.startTimer()
- .stopTimer()
- .setOutgoingInvocationId(invocationId)
- .setTargetServiceName(targetServiceName)
- .setTargetEntity(targetEntity)
- .setStatusCode(ONAPLogConstants.ResponseStatus.COMPLETE.name())
- .setKeyRequestId(requestID)
- .setServiceName(serviceName);
+ metric.startTimer().stopTimer().setOutgoingInvocationId(invocationId).setTargetServiceName(targetServiceName).setTargetEntity(targetEntity)
+ .setStatusCode(ONAPLogConstants.ResponseStatus.COMPLETE.name()).setKeyRequestId(requestID).setServiceName(serviceName);
metric.log(ONAPLogConstants.Markers.INVOKE, LogLevel.INFO, msg, params);
}
public void invokeReturn(String msg, Object... params) {
try {
- metric.startTimer()
- .stopTimer();
+ metric.startTimer().stopTimer();
} catch (Exception e) {
error(e.getMessage(), e);
}
@@ -334,15 +332,17 @@ public class Logger implements org.slf4j.Logger {
}
}
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
- public void warn(String msg, Object... params){
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ public void warn(String msg, Object... params) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, params);
}
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(String msg, Object o, Object o1) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, o, o1);
@@ -350,7 +350,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(String msg, Throwable throwable) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, throwable);
@@ -363,7 +364,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(Marker marker, String msg) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg);
@@ -371,7 +373,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(Marker marker, String msg, Object o) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, o);
@@ -379,7 +382,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(Marker marker, String msg, Object o, Object o1) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, o, o1);
@@ -387,7 +391,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(Marker marker, String msg, Object... objects) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, objects);
@@ -395,22 +400,25 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
public void warn(Marker marker, String msg, Throwable throwable) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, msg, throwable);
}
}
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
- public void error(String msg, Object... params){
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ public void error(String msg, Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, params);
}
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(String msg, Throwable throwable) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, throwable);
@@ -423,7 +431,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(Marker marker, String msg) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg);
@@ -431,7 +440,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(Marker marker, String msg, Object o) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, o);
@@ -439,7 +449,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(Marker marker, String msg, Object o, Object o1) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, o, o1);
@@ -447,7 +458,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(Marker marker, String msg, Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, params);
@@ -455,22 +467,25 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(Marker marker, String msg, Throwable throwable) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, throwable);
}
}
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
- public void error(String msg){
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ public void error(String msg) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg);
}
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(String msg, Object o) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, o);
@@ -478,7 +493,8 @@ public class Logger implements org.slf4j.Logger {
}
@Override
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
public void error(String msg, Object o, Object o1) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, msg, o, o1);
@@ -487,17 +503,15 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out ERROR logging level message to the application error log
- * @param errorLevel code representing the error severity level
- * @param serviceName name of the API invoked at the logging component
- * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
+ *
+ * @param errorLevel code representing the error severity level
+ * @param serviceName name of the API invoked at the logging component
+ * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
* @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param params optional parameters of a given error description
*/
- public void error(EcompErrorSeverity errorLevel,
- EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String targetEntity,
- String errorDescription, Object...params) {
+ public void error(EcompErrorSeverity errorLevel, EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity,
+ String errorDescription, Object... params) {
if (isErrorEnabled()) {
error.log(errorLevel, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
}
@@ -505,17 +519,20 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out ERROR logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
- * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
+ * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
* @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param params optional parameters of a given error description
*/
- @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, ErrorLogOptionalData, String, Object...)} **/
+
+ @Deprecated
+ /** Please use method {@link #error(EcompLoggerErrorCode, String, ErrorLogOptionalData, String, Object...)} **/
public void error(EcompLoggerErrorCode errorCodeEnum,
String serviceName,
String targetEntity,
- String errorDescription, Object...params) {
+ String errorDescription, Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
}
@@ -526,25 +543,21 @@ public class Logger implements org.slf4j.Logger {
* @param errorDescription a human readable description of the error condition
* @param params optional parameters of a given error description
*/
-
- public void error(EcompLoggerErrorCode errorCodeEnum, String serviceName,
- String errorDescription, Object...params) {
- error(errorCodeEnum, serviceName, (String)null, errorDescription, params);
+ public void error(EcompLoggerErrorCode errorCodeEnum, String serviceName, String errorDescription, Object... params) {
+ error(errorCodeEnum, serviceName, (String) null, errorDescription, params);
}
/**
* Writes out ERROR logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
* @param errorLogOptionalData elements that contans all relevant data of the error
- * @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
*/
- public void error(EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- ErrorLogOptionalData errorLogOptionalData,
- String errorDescription,
- Object...params) {
+ public void error(EcompLoggerErrorCode errorCodeEnum, String serviceName, ErrorLogOptionalData errorLogOptionalData, String errorDescription,
+ Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.ERROR, errorCodeEnum, serviceName, errorLogOptionalData, errorDescription, params);
}
@@ -552,16 +565,14 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out WARN logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
- * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
+ * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
* @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param params optional parameters of a given error description
*/
- public void warn(EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String targetEntity,
- String errorDescription, Object...params) {
+ public void warn(EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity, String errorDescription, Object... params) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
}
@@ -569,16 +580,15 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out WARN logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
* @param errorLogOptionalData elements that contans all relevant data of the error
- * @param description a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param description a human readable description of the error condition
+ * @param params optional parameters of a given error description
*/
- public void warn(EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- ErrorLogOptionalData errorLogOptionalData,
- String description, Object...params) {
+ public void warn(EcompLoggerErrorCode errorCodeEnum, String serviceName, ErrorLogOptionalData errorLogOptionalData, String description,
+ Object... params) {
if (isWarnEnabled()) {
error.log(LogLevel.WARN, errorCodeEnum, serviceName, errorLogOptionalData, description, params);
}
@@ -586,31 +596,28 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out WARN logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
* @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param params optional parameters of a given error description
*/
- public void warn(EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String errorDescription, Object...params) {
+ public void warn(EcompLoggerErrorCode errorCodeEnum, String serviceName, String errorDescription, Object... params) {
if (isWarnEnabled()) {
- error.log(LogLevel.WARN, errorCodeEnum, serviceName, (String)null, errorDescription, params);
+ error.log(LogLevel.WARN, errorCodeEnum, serviceName, (String) null, errorDescription, params);
}
}
/**
* Writes out FATAL logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
- * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
+ * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
* @param errorDescription a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param params optional parameters of a given error description
*/
- public void fatal(EcompLoggerErrorCode errorCodeEnum,
- String serviceName,
- String targetEntity,
- String errorDescription, Object...params) {
+ public void fatal(EcompLoggerErrorCode errorCodeEnum, String serviceName, String targetEntity, String errorDescription, Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.FATAL, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
}
@@ -618,18 +625,17 @@ public class Logger implements org.slf4j.Logger {
/**
* Writes out FATAL logging level message to the application error log
- * @param errorCodeEnum code representing the error condition
- * @param serviceName name of the API invoked at the logging component
+ *
+ * @param errorCodeEnum code representing the error condition
+ * @param serviceName name of the API invoked at the logging component
* @param errorLogOptionalData elements that contans all relevant data of the error
- * @param description a human readable description of the error condition
- * @param params optional parameters of a given error description
+ * @param description a human readable description of the error condition
+ * @param params optional parameters of a given error description
*/
- public void fatal(EcompLoggerErrorCode errorCodeEnum, String serviceName,
- ErrorLogOptionalData errorLogOptionalData,
- String description, Object...params) {
+ public void fatal(EcompLoggerErrorCode errorCodeEnum, String serviceName, ErrorLogOptionalData errorLogOptionalData, String description,
+ Object... params) {
if (isErrorEnabled()) {
error.log(LogLevel.FATAL, errorCodeEnum, serviceName, errorLogOptionalData, description, params);
}
}
}
-
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java
index b8c1b268e1..f68fbe155d 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java
@@ -1,10 +1,13 @@
package org.openecomp.sdc.common.log.wrappers;
+import java.util.UUID;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.openecomp.sdc.common.log.enums.ConstantsLogging;
import org.openecomp.sdc.common.log.elements.LoggerAudit;
import org.openecomp.sdc.common.log.elements.LoggerFactory;
+import org.openecomp.sdc.common.log.enums.ConstantsLogging;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.enums.LogLevel;
import org.openecomp.sdc.common.log.enums.Severity;
@@ -12,146 +15,87 @@ import org.openecomp.sdc.common.log.utils.LoggingThreadLocalsHolder;
import org.slf4j.MDC;
import org.slf4j.Marker;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.core.Response;
-import java.util.UUID;
-
-
/**
* Created by dd4296 on 12/19/2017.
- *
- * audit log for asdc using the log library
- * this is adapted for filter classes
+ * <p>
+ * audit log for asdc using the log library this is adapted for filter classes
*/
public class LoggerSdcAudit extends LoggerSdcUtilBase {
private static String AUDIT_ON = "auditOn";
- private String className;
private final LoggerAudit ecompLoggerAudit;
+ private String className;
public LoggerSdcAudit(Class<?> clazz) {
this.className = clazz.getName();
ecompLoggerAudit = LoggerFactory.getMdcLogger(LoggerAudit.class, org.slf4j.LoggerFactory.getLogger(clazz));
}
+ public static boolean isFlowBeingTakenCare() {
+ String auditOn = MDC.get(AUDIT_ON);
+ return !StringUtils.isEmpty(auditOn) && "true".equals(auditOn);
+ }
+
public void startLog(ContainerRequestContext requestContext) {
- ecompLoggerAudit.clear()
- .startTimer()
- .setPartnerName(getPartnerName(
- requestContext.getHeaderString("user-agent"),
- requestContext.getHeaderString("USER_ID"),
- getUrl(requestContext),
- requestContext.getHeaderString("X-ONAP-PartnerName")))
- .setServiceName(getServiceName(requestContext))
- .setKeyRequestId(LoggingThreadLocalsHolder.getUuid())
- .setKeyInvocationId(UUID.randomUUID().toString());
+ ecompLoggerAudit.clear().startTimer().setPartnerName(
+ getPartnerName(requestContext.getHeaderString("user-agent"), requestContext.getHeaderString("USER_ID"), getUrl(requestContext),
+ requestContext.getHeaderString("X-ONAP-PartnerName"))).setServiceName(getServiceName(requestContext))
+ .setKeyRequestId(LoggingThreadLocalsHolder.getUuid()).setKeyInvocationId(UUID.randomUUID().toString());
MDC.put(AUDIT_ON, "true");
}
public void startAuditFetchLog(String partnerName, String serviceName) {
- ecompLoggerAudit.clear()
- .startTimer()
- .setPartnerName(partnerName)
- .setServiceName(serviceName)
- .setOptClassName(serviceName);
+ ecompLoggerAudit.clear().startTimer().setPartnerName(partnerName).setServiceName(serviceName).setOptClassName(serviceName);
MDC.put(AUDIT_ON, "true");
}
- public static boolean isFlowBeingTakenCare() {
- String auditOn = MDC.get(AUDIT_ON);
- return !StringUtils.isEmpty(auditOn) && "true".equals(auditOn);
- }
-
//this function clears the MDC data that relevant for this class
- public void clearMyData(){
+ public void clearMyData() {
ecompLoggerAudit.clear();
}
- public void logExit(String remoteAddress,
- ContainerRequestContext requestContext,
- Response.StatusType statusInfo,
- LogLevel logLevel,
- Severity securityLevel,
- String message,
- Marker marker) {
-
+ public void logExit(String remoteAddress, ContainerRequestContext requestContext, Response.StatusType statusInfo, LogLevel logLevel,
+ Severity securityLevel, String message, Marker marker) {
try {
-
- String msg = ecompLoggerAudit.getAuditMessage() == null ?
- message : ecompLoggerAudit.getAuditMessage();
- ecompLoggerAudit.stopTimer()
- .setRemoteHost(remoteAddress)
- .setResponseCode(convertHttpCodeToErrorCode(statusInfo.getStatusCode()))
- .setStatusCodeByResponseCode(Integer.toString(statusInfo.getStatusCode()))
- .setResponseDesc(statusInfo.getReasonPhrase())
- .setInstanceUUID(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_INSTANCE_ID_HEADER))
- .setOptServiceInstanceId(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER))
- .setOptClassName(className)
- .setOptAlertSeverity(securityLevel)
- .log(marker, logLevel, msg);
- }
- catch (Exception e) {
+ String msg = ecompLoggerAudit.getAuditMessage() == null ? message : ecompLoggerAudit.getAuditMessage();
+ ecompLoggerAudit.stopTimer().setRemoteHost(remoteAddress).setResponseCode(convertHttpCodeToErrorCode(statusInfo.getStatusCode()))
+ .setStatusCodeByResponseCode(Integer.toString(statusInfo.getStatusCode())).setResponseDesc(statusInfo.getReasonPhrase())
+ .setInstanceUUID(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_INSTANCE_ID_HEADER))
+ .setOptServiceInstanceId(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER)).setOptClassName(className)
+ .setOptAlertSeverity(securityLevel).log(marker, logLevel, msg);
+ } catch (Exception e) {
log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
- }
- finally {
- MDC.put(AUDIT_ON,"false");
+ } finally {
+ MDC.put(AUDIT_ON, "false");
}
}
- public void logEntry(String remoteAddress,
- ContainerRequestContext requestContext,
- LogLevel logLevel,
- Severity securityLevel,
- String message,
- Marker marker) {
-
+ public void logEntry(String remoteAddress, ContainerRequestContext requestContext, LogLevel logLevel, Severity securityLevel, String message,
+ Marker marker) {
try {
-
- String msg = ecompLoggerAudit.getAuditMessage() == null ?
- message : ecompLoggerAudit.getAuditMessage();
- ecompLoggerAudit.stopTimer()
- .setRemoteHost(remoteAddress)
- .setResponseCode(EcompLoggerErrorCode.SUCCESS)
- .setStatusCode(ONAPLogConstants.ResponseStatus.INPROGRESS.name())
- .setResponseDesc("")
- .setInstanceUUID(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_INSTANCE_ID_HEADER))
- .setOptServiceInstanceId(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER))
- .setOptClassName(className)
- .setOptAlertSeverity(securityLevel)
- .log(marker, logLevel, msg);
- }
- catch (Exception e) {
+ String msg = ecompLoggerAudit.getAuditMessage() == null ? message : ecompLoggerAudit.getAuditMessage();
+ ecompLoggerAudit.stopTimer().setRemoteHost(remoteAddress).setResponseCode(EcompLoggerErrorCode.SUCCESS)
+ .setStatusCode(ONAPLogConstants.ResponseStatus.INPROGRESS.name()).setResponseDesc("")
+ .setInstanceUUID(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_INSTANCE_ID_HEADER))
+ .setOptServiceInstanceId(requestContext.getHeaderString(ConstantsLogging.X_ECOMP_SERVICE_ID_HEADER)).setOptClassName(className)
+ .setOptAlertSeverity(securityLevel).log(marker, logLevel, msg);
+ } catch (Exception e) {
log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
- }
- finally {
- MDC.put(AUDIT_ON,"false");
+ } finally {
+ MDC.put(AUDIT_ON, "false");
}
}
- public void logEntry(LogLevel logLevel,
- Severity securityLevel,
- String message,
- Marker marker,
- String requestId) {
-
+ public void logEntry(LogLevel logLevel, Severity securityLevel, String message, Marker marker, String requestId) {
try {
-
- String msg = ecompLoggerAudit.getAuditMessage() == null ?
- message : ecompLoggerAudit.getAuditMessage();
- ecompLoggerAudit.stopTimer()
- .setKeyRequestId(requestId)
- .setResponseCode(EcompLoggerErrorCode.SUCCESS)
- .setStatusCode(ONAPLogConstants.ResponseStatus.COMPLETE.name())
- .setResponseDesc("")
- .setOptAlertSeverity(securityLevel)
- .log(marker, logLevel, msg);
- }
- catch (Exception e) {
+ String msg = ecompLoggerAudit.getAuditMessage() == null ? message : ecompLoggerAudit.getAuditMessage();
+ ecompLoggerAudit.stopTimer().setKeyRequestId(requestId).setResponseCode(EcompLoggerErrorCode.SUCCESS)
+ .setStatusCode(ONAPLogConstants.ResponseStatus.COMPLETE.name()).setResponseDesc("").setOptAlertSeverity(securityLevel)
+ .log(marker, logLevel, msg);
+ } catch (Exception e) {
log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
- }
- finally {
- MDC.put(AUDIT_ON,"false");
+ } finally {
+ MDC.put(AUDIT_ON, "false");
}
}
-
}
diff --git a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
index 6ca71281d3..87c2c2d759 100644
--- a/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
@@ -1,21 +1,34 @@
package org.openecomp.sdc.common.log.wrappers;
+import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
+import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT;
+import static java.net.HttpURLConnection.HTTP_CONFLICT;
+import static java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE;
+import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
+import static java.net.HttpURLConnection.HTTP_GONE;
+import static java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED;
+import static java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE;
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED;
+import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
+import static java.net.HttpURLConnection.HTTP_PROXY_AUTH;
+import static java.net.HttpURLConnection.HTTP_REQ_TOO_LONG;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+import static java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE;
+
+import java.util.List;
+import java.util.StringTokenizer;
+import javax.ws.rs.container.ContainerRequestContext;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.container.ContainerRequestContext;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import static java.net.HttpURLConnection.*;
-
/**
* Created by dd4296 on 12/20/2017.
- *
- * base class for metric and audit log logging
- * holding the specific logic for data extraction
+ * <p>
+ * base class for metric and audit log logging holding the specific logic for data extraction
*/
public class LoggerSdcUtilBase {
@@ -23,20 +36,18 @@ public class LoggerSdcUtilBase {
String getRequestIDfromHeaders(List<Object> requestHeader) {
// this method gets list of type object.
+
// toString method returns the RequestId with brackets.
String requestHeaderString = requestHeader.toString();
- return requestHeaderString.replace("[","").replace("]","");
+ return requestHeaderString.replace("[", "").replace("]", "");
}
-
-
-
// this method translates http error code to ECOMP Logger Error code
+
// this is a naive translation and is not a result of any documented format ECOMP specification
protected EcompLoggerErrorCode convertHttpCodeToErrorCode(int httpResponseCode) {
if (isSuccessError(httpResponseCode)) {
return EcompLoggerErrorCode.SUCCESS;
}
-
if (isSchemaError(httpResponseCode)) {
return EcompLoggerErrorCode.SCHEMA_ERROR;
}
@@ -56,7 +67,6 @@ public class LoggerSdcUtilBase {
}
private boolean isTimeoutOrAvailabilityError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_BAD_REQUEST:
case HTTP_UNAUTHORIZED:
@@ -67,11 +77,9 @@ public class LoggerSdcUtilBase {
default:
return false;
}
-
}
private boolean isPermissionsError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_PAYMENT_REQUIRED:
case HTTP_FORBIDDEN:
@@ -79,12 +87,10 @@ public class LoggerSdcUtilBase {
case HTTP_PROXY_AUTH:
return true;
}
-
return false;
}
private boolean isDataError(int httpResponseCode) {
-
switch (httpResponseCode) {
case HTTP_NOT_ACCEPTABLE:
case HTTP_LENGTH_REQUIRED:
@@ -94,7 +100,6 @@ public class LoggerSdcUtilBase {
case HTTP_UNSUPPORTED_TYPE:
return true;
}
-
return false;
}
@@ -111,28 +116,23 @@ public class LoggerSdcUtilBase {
}
protected String getPartnerName(String userAgent, String userId, String url, String xOnapPartnerName) {
-
//On called side (receiver) If the API call is authenticated, then log the userid/mechid (fully qualified if that is what was provided)
if (isFound(userId)) {
return userId;
}
-
String urlUser = getUserIdFromUrl(url);
if (isFound(urlUser)) {
return urlUser;
}
-
//Otherwise, if X-ONAP-PartnerName was provided, then log that
- if (isFound(xOnapPartnerName)){
+ if (isFound(xOnapPartnerName)) {
return xOnapPartnerName;
}
-
//Otherwise, for an HTTP API call, log the part of the URI specifying the agent that the caller used to make the call
String userAgentName = getUserIdFromUserAgent(userAgent);
if (isFound(userAgentName)) {
return userAgentName;
}
-
return "UNKNOWN";
}
@@ -141,15 +141,12 @@ public class LoggerSdcUtilBase {
if (userAgent.toLowerCase().contains("firefox")) {
return "fireFox_FE";
}
-
if (userAgent.toLowerCase().contains("msie")) {
return "explorer_FE";
}
-
if (userAgent.toLowerCase().contains("chrome")) {
return "chrome_FE";
}
-
return userAgent;
}
return null;
@@ -169,7 +166,6 @@ public class LoggerSdcUtilBase {
protected String getUrl(ContainerRequestContext requestContext) {
String url = "";
-
try {
if (requestContext.getUriInfo() != null && requestContext.getUriInfo().getRequestUri() != null) {
url = requestContext.getUriInfo().getRequestUri().toURL().toString();
@@ -177,13 +173,11 @@ public class LoggerSdcUtilBase {
} catch (Exception ex) {
log.error("failed to get url from request context ", ex);
}
-
return url;
}
protected String getServiceName(ContainerRequestContext requestContext) {
- return (requestContext.getUriInfo().getRequestUri().toString())
- .replace(requestContext.getUriInfo().getBaseUri().toString(), "/");
+ return (requestContext.getUriInfo().getRequestUri().toString()).replace(requestContext.getUriInfo().getBaseUri().toString(), "/");
}
private boolean isFound(String value) {
@@ -192,4 +186,4 @@ public class LoggerSdcUtilBase {
}
return false;
}
-} \ No newline at end of file
+}