aboutsummaryrefslogtreecommitdiffstats
path: root/common-app-logging/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'common-app-logging/src/main/java/org')
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java181
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java39
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/LogConfigurationConstants.java49
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java60
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java504
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java173
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java224
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerDebug.java75
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java163
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java82
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java193
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java101
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java33
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java25
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java67
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java30
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java39
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java85
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java40
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java38
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java42
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java45
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java656
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java177
-rw-r--r--common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java204
25 files changed, 3325 insertions, 0 deletions
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
new file mode 100644
index 0000000000..7d1783314f
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogFieldsHandler.java
@@ -0,0 +1,181 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.api;
+
+import org.openecomp.sdc.common.log.enums.Severity;
+
+public interface ILogFieldsHandler {
+ void startAuditTimer();
+
+ void startMetricTimer();
+
+ void stopAuditTimer();
+
+ void stopMetricTimer();
+
+ void setClassName(String className);
+
+ void setServerFQDN(String serverFQDN);
+
+ void setServerIPAddress(String serverIPAddress);
+
+ // intended for setting this parameter in a given thread
+ void setServerFQDNInternally();
+
+ // intended for setting this parameter in a given thread
+ void setServerIPAddressInternally();
+
+ void setInstanceUUID(String instanceUUID);
+
+ void setProcessKey(String processKey);
+
+ void setAlertSeverity(Severity alertSeverity);
+
+ void setOptCustomField1(String customField1);
+
+ 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();
+
+ String getServiceName();
+
+ String getTargetEntity();
+
+ String getTargetServiceName();
+
+ String getErrorCategory();
+
+ void clear();
+
+ boolean isMDCParamEmpty(String mdcKeyName);
+
+ String getFqdn();
+
+ String getHostAddress();
+
+ String getKeyRequestId();
+
+ void removeStatusCode();
+
+ void removePartnerName();
+
+ void removeResponseCode();
+
+ void removeResponseDesc();
+
+ void removeServiceInstanceId();
+
+ void removeTargetEntity();
+
+ void removeTargetServiceName();
+
+ void removeTargetVirtualEntity();
+
+ void removeErrorCode();
+
+ void removeErrorCategory();
+
+ void removeErrorDescription();
+
+ void setAuditMessage(String message);
+
+ String getAuditMessage();
+
+ //service supportability [US 496441]
+
+ String getSupportablityAction();
+
+ String getSupportablityCsarUUID();
+
+ String getSupportablityCsarVersion();
+
+ String getSupportablityComponentName();
+
+ String getSupportablityComponentUUID();
+
+ String getSupportablityComponentVersion();
+
+ String getSupportablityStatusCode();
+
+ void setSupportablityAction(String action);
+
+ void setSupportablityCsarUUID(String uuid);
+
+ void setSupportablityCsarVersion(String version);
+
+ void setSupportablityComponentName(String name);
+
+ void setSupportablityComponentUUID(String UUID);
+
+ void setSupportablityComponentVersion(String version);
+
+ void setSupportablityStatusCode(String statusCode);
+
+ void removeSupportablityAction();
+
+ void removeSupportablityComponentName();
+
+ void removeSupportablityComponentUUID();
+
+ void removeSupportablityComponentVersion();
+
+ void removeSupportablityCsarUUID();
+
+ void removeSupportablityCsarVersion();
+
+ void removeSupportablityStatusCode();
+
+ String getPartnerName();
+
+ String getRemoteHost();
+
+ String getServerIpAddress();
+
+ void setKeyInvocationId(String invocationId);
+
+ CharSequence getKeyInvocationId();
+}
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
new file mode 100644
index 0000000000..866498cefd
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/ILogger.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.common.log.api;
+
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.slf4j.Marker;
+
+import java.util.List;
+
+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/api/LogConfigurationConstants.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/LogConfigurationConstants.java
new file mode 100644
index 0000000000..d1d5a3af7c
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/api/LogConfigurationConstants.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.api;
+
+public final class LogConfigurationConstants {
+
+ public static final String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceID";
+ public static final String MDC_SERVER_IP_ADDRESS = "ServerIPAddress";
+ public static final String MDC_REMOTE_HOST = "RemoteHost";
+ public static final String MDC_AUDIT_MESSAGE = "AuditMessage";
+ public static final String MDC_END_TIMESTAMP = "EndTimestamp";
+ public static final String MDC_ELAPSED_TIME = "ElapsedTime";
+ public static final String MDC_PROCESS_KEY = "ProcessKey";
+ public static final String MDC_TARGET_VIRTUAL_ENTITY = "TargetVirtualEntity";
+ public static final String MDC_ERROR_CATEGORY = "ErrorCategory";
+ public static final String MDC_ERROR_CODE = "ErrorCode";
+ public static final String MDC_ERROR_DESC = "ErrorDescription";
+ public static final String MDC_CLASS_NAME = "ClassName";
+ public static final String MDC_OPT_FIELD1 = "CustomField1";
+ public static final String MDC_OPT_FIELD2 = "CustomField2";
+ public static final String MDC_OPT_FIELD3 = "CustomField3";
+ public static final String MDC_OPT_FIELD4 = "CustomField4";
+ public static final String MDC_OUTGOING_INVOCATION_ID = "OutgoingInvocationId";
+ public static final String MDC_SUPPORTABLITY_ACTION = "SupportablityAction";
+ public static final String MDC_SUPPORTABLITY_CSAR_UUID = "SupportablityCsarUUID";
+ public static final String MDC_SUPPORTABLITY_CSAR_VERSION = "SupportablityCsarVersion";
+ public static final String MDC_SUPPORTABLITY_COMPONENT_NAME = "SupportablityComponentName";
+ public static final String MDC_SUPPORTABLITY_COMPONENT_UUID = "SupportablityComponentUUID";
+ public static final String MDC_SUPPORTABLITY_COMPONENT_VERSION = "SupportablityComponentVersion";
+ public static final String MDC_SUPPORTABLITY_STATUS_CODE = "SupportablityStatus";
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..d5279b1101
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/ErrorLogOptionalData.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+public class ErrorLogOptionalData {
+ private String targetEntity;
+ private String targetServiceName;
+
+ String getTargetEntity() {
+ return targetEntity;
+ }
+
+ String getTargetServiceName() {
+ return targetServiceName;
+ }
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private final ErrorLogOptionalData instance;
+
+ private Builder() {
+ instance = new ErrorLogOptionalData();
+ }
+
+ public Builder targetEntity(String targetEntity) {
+ instance.targetEntity = targetEntity;
+ return this;
+ }
+
+ public Builder targetServiceName(String targetServiceName) {
+ instance.targetServiceName = targetServiceName;
+ return this;
+ }
+
+ public ErrorLogOptionalData build() {
+ return instance;
+ }
+ }
+}
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
new file mode 100644
index 0000000000..361c255009
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandler.java
@@ -0,0 +1,504 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.api.LogConfigurationConstants;
+import org.openecomp.sdc.common.log.enums.ConstantsLogging;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+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;
+
+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 HH:mm:ss.SSSz";
+ private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter
+ .ofPattern(dateFormatPattern);
+ protected static Logger log = LoggerFactory.getLogger(LogFieldsMdcHandler.class.getName());
+ protected static String hostAddress;
+ private 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(LogConfigurationConstants.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(LogConfigurationConstants.MDC_END_TIMESTAMP, generatedTimeNow());
+ setElapsedTime(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP));
+ }
+
+ @Override
+ public void setClassName(String className) {
+ MDC.put(LogConfigurationConstants.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(LogConfigurationConstants.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(LogConfigurationConstants.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(LogConfigurationConstants.MDC_OPT_FIELD1, customField1);
+ }
+
+ @Override
+ public void setOutgoingInvocationId(String outgoingInvocationId) {
+ MDC.put(LogConfigurationConstants.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(LogConfigurationConstants.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(LogConfigurationConstants.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(LogConfigurationConstants.MDC_TARGET_VIRTUAL_ENTITY, targetVirtualEntity);
+ }
+
+ @Override
+ public void setErrorCode(int errorCode) {
+ MDC.put(LogConfigurationConstants.MDC_ERROR_CODE, Integer.toString(errorCode));
+ }
+
+ @Override
+ public void setErrorCategory(String errorCategory) {
+ MDC.put(LogConfigurationConstants.MDC_ERROR_CATEGORY, errorCategory);
+ }
+
+ @Override
+ public String getErrorCode() {
+ return MDC.get(LogConfigurationConstants.MDC_ERROR_CODE);
+ }
+
+ @Override
+ public String getServiceName() {
+ return MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME);
+ }
+
+ @Override
+ public String getErrorCategory() {
+ return MDC.get(LogConfigurationConstants.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(LogConfigurationConstants.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(LogConfigurationConstants.MDC_TARGET_VIRTUAL_ENTITY);
+ }
+
+ @Override
+ public void removeErrorCode() {
+ MDC.remove(LogConfigurationConstants.MDC_ERROR_CODE);
+ }
+
+ @Override
+ public void removeErrorCategory() {
+ MDC.remove(LogConfigurationConstants.MDC_ERROR_CATEGORY);
+ }
+
+ @Override
+ public void removeErrorDescription() {
+ MDC.remove(LogConfigurationConstants.MDC_ERROR_DESC);
+ }
+
+ @Override
+ public void setAuditMessage(String message) {
+ MDC.put(LogConfigurationConstants.MDC_AUDIT_MESSAGE, message);
+ }
+
+ @Override
+ public String getAuditMessage() {
+ return MDC.get(LogConfigurationConstants.MDC_AUDIT_MESSAGE);
+ }
+
+ @Override
+ public String getSupportablityStatusCode() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_STATUS_CODE);
+ }
+
+ @Override
+ public String getSupportablityAction() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_ACTION);
+
+ }
+
+
+ @Override
+ public String getRemoteHost() {
+ return MDC.get(LogConfigurationConstants.MDC_REMOTE_HOST);
+ }
+
+ @Override
+ public String getServerIpAddress() {
+ return MDC.get(LogConfigurationConstants.MDC_SERVER_IP_ADDRESS);
+ }
+
+ @Override
+ public String getSupportablityCsarUUID() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_UUID);
+ }
+
+ @Override
+ public String getSupportablityCsarVersion() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_VERSION);
+
+ }
+
+ @Override
+ public String getSupportablityComponentName() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_NAME);
+ }
+
+ @Override
+ public String getSupportablityComponentUUID() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_UUID);
+
+ }
+
+ @Override
+ public String getSupportablityComponentVersion() {
+ return MDC.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_VERSION);
+ }
+
+ @Override
+ public String getKeyInvocationId() {
+ return MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
+ }
+
+ @Override
+ public void setSupportablityStatusCode(String statusCode) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_STATUS_CODE, statusCode);
+ }
+
+ @Override
+ public void setSupportablityAction(String action) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_ACTION, action);
+ }
+
+ @Override
+ public void setSupportablityCsarUUID(String uuid) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_UUID, uuid);
+ }
+
+ @Override
+ public void setSupportablityCsarVersion(String version) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_VERSION, version);
+ }
+
+ @Override
+ public void setSupportablityComponentName(String name) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_NAME, name);
+ }
+
+ @Override
+ public void setSupportablityComponentUUID(String uuid) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_UUID, uuid);
+ }
+
+ @Override
+ public void setSupportablityComponentVersion(String version) {
+ MDC.put(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_VERSION, version);
+ }
+
+ @Override
+ public void removeSupportablityAction() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_ACTION);
+ }
+
+ @Override
+ public void removeSupportablityComponentName() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_NAME);
+ }
+
+ @Override
+ public void removeSupportablityComponentUUID() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_UUID);
+ }
+
+ @Override
+ public void removeSupportablityComponentVersion() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_VERSION);
+ }
+
+ @Override
+ public void removeSupportablityCsarUUID() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_UUID);
+ }
+
+ @Override
+ public void removeSupportablityCsarVersion() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_VERSION);
+ }
+
+ @Override
+ public void removeSupportablityStatusCode() {
+ MDC.remove(LogConfigurationConstants.MDC_SUPPORTABLITY_STATUS_CODE);
+ }
+
+ @Override
+ public String getPartnerName() {
+ return MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
+ }
+
+ private void setElapsedTime(String beginTimestamp) {
+ try {
+ final LocalDateTime startTime = LocalDateTime.parse(beginTimestamp, dateTimeFormatter);
+ final LocalDateTime endTime = LocalDateTime
+ .parse(MDC.get(LogConfigurationConstants.MDC_END_TIMESTAMP), dateTimeFormatter);
+ final Duration timeDifference = Duration.between(startTime, endTime);
+
+ MDC.put(LogConfigurationConstants.MDC_ELAPSED_TIME, String.valueOf(timeDifference.toMillis()));
+
+ } catch (Exception ex) {
+ log.error("failed to calculate elapsed time", ex);
+ }
+ }
+
+ private String generatedTimeNow() {
+ return dateTimeFormatter
+ .withZone(ZoneOffset.UTC)
+ .format(Instant.now());
+ }
+
+ 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);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..502b7a6871
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerAudit.java
@@ -0,0 +1,173 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.api.LogConfigurationConstants;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.enums.Severity;
+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 List<String> mandatoryFields = new ArrayList<>(Arrays.asList(
+ ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
+ LogConfigurationConstants.MDC_END_TIMESTAMP,
+ ONAPLogConstants.MDCs.REQUEST_ID,
+ ONAPLogConstants.MDCs.SERVICE_NAME,
+ ONAPLogConstants.MDCs.PARTNER_NAME,
+ ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE,
+ ONAPLogConstants.MDCs.RESPONSE_CODE,
+ LogConfigurationConstants.MDC_SERVICE_INSTANCE_ID,
+ ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION,
+ LogConfigurationConstants.MDC_ELAPSED_TIME,
+ LogConfigurationConstants.MDC_SERVER_IP_ADDRESS,
+ ONAPLogConstants.MDCs.SERVER_FQDN));
+
+ private static List<String> optionalFields = new ArrayList<>(Arrays.asList(
+ ONAPLogConstants.MDCs.INSTANCE_UUID,
+ ONAPLogConstants.MDCs.RESPONSE_SEVERITY,
+ LogConfigurationConstants.MDC_REMOTE_HOST,
+ LogConfigurationConstants.MDC_CLASS_NAME,
+ LogConfigurationConstants.MDC_PROCESS_KEY,
+ LogConfigurationConstants.MDC_OPT_FIELD1,
+ LogConfigurationConstants.MDC_OPT_FIELD2,
+ LogConfigurationConstants.MDC_OPT_FIELD3,
+ LogConfigurationConstants.MDC_OPT_FIELD4));
+
+ LoggerAudit(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
+ //TODO Andrey, set default marker
+ 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();
+ }
+
+ @Override
+ public LoggerAudit startTimer() {
+ ecompLogFieldsHandler.startAuditTimer();
+ return this;
+ }
+
+ public LoggerAudit stopTimer() {
+ ecompLogFieldsHandler.stopAuditTimer();
+ return this;
+ }
+
+ public LoggerAudit setInstanceUUID(String instanceUUID) {
+ ecompLogFieldsHandler.setInstanceUUID(instanceUUID);
+ return this;
+ }
+
+ public LoggerAudit setOptClassName(String className) {
+ MDC.put(LogConfigurationConstants.MDC_CLASS_NAME, className);
+ return this;
+ }
+
+ public LoggerAudit setOptProcessKey(String processKey) {
+ ecompLogFieldsHandler.setProcessKey(processKey);
+ return this;
+ }
+
+ public LoggerAudit setOptAlertSeverity(Severity alertSeverity) {
+ ecompLogFieldsHandler.setAlertSeverity(alertSeverity);
+ return this;
+ }
+
+ @Override
+ public LoggerAudit setKeyRequestId(String keyRequestId) {
+ return (LoggerAudit) super.setKeyRequestId(keyRequestId);
+ }
+
+ @Override
+ public LoggerAudit setKeyInvocationId(String keyInvocationId) {
+ ecompLogFieldsHandler.setKeyInvocationId(keyInvocationId);
+ return this;
+ }
+
+ public LoggerAudit setRemoteHost(String remoteHost) {
+ ecompLogFieldsHandler.setRemoteHost(remoteHost);
+ return this;
+ }
+
+ public LoggerAudit setServiceName(String serviceName) {
+ ecompLogFieldsHandler.setServiceName(serviceName);
+ return this;
+ }
+
+ public LoggerAudit setStatusCodeByResponseCode(String responseCode) {
+ String respStatus = Integer.parseInt(responseCode) / 100 == 2 ? ONAPLogConstants.ResponseStatus.COMPLETE.name() : ONAPLogConstants.ResponseStatus.ERROR.name();
+ ecompLogFieldsHandler.setStatusCode(respStatus);
+ return this;
+ }
+
+ public LoggerAudit setStatusCode(String statusCode) {
+ ecompLogFieldsHandler.setStatusCode(statusCode);
+ return this;
+ }
+
+
+ public LoggerAudit setPartnerName(String partnerName) {
+ ecompLogFieldsHandler.setPartnerName(partnerName);
+ return this;
+ }
+
+ public LoggerAudit setResponseCode(EcompLoggerErrorCode responseCode) {
+ ecompLogFieldsHandler.setResponseCode(responseCode.getErrorCode());
+ return this;
+ }
+
+ public LoggerAudit setResponseDesc(String responseDesc) {
+ ecompLogFieldsHandler.setResponseDesc(responseDesc);
+ return this;
+ }
+
+ public LoggerAudit setOptServiceInstanceId(String serviceInstanceId) {
+ ecompLogFieldsHandler.setServiceInstanceId(serviceInstanceId);
+ return this;
+ }
+
+ public String getAuditMessage() {
+ return ecompLogFieldsHandler.getAuditMessage();
+ }
+
+
+ @Override
+ public List<String> getMandatoryFields() {
+ return Collections.unmodifiableList(mandatoryFields);
+ }
+
+ @Override
+ public LoggerAudit clear() {
+ super.clear();
+ ecompLogFieldsHandler.setServerFQDNInternally();
+ 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
new file mode 100644
index 0000000000..5b2bfad5b9
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerBase.java
@@ -0,0 +1,224 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.api.ILogger;
+import org.openecomp.sdc.common.log.enums.ConstantsLogging;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.LogMarkers;
+import org.openecomp.sdc.common.log.utils.LoggingThreadLocalsHolder;
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+public abstract class LoggerBase implements ILogger {
+ private final Logger myLogger;
+ private final Marker myMarker;
+ protected final ILogFieldsHandler ecompLogFieldsHandler;
+ private final static String missingLogFieldsMsg = "mandatory parameters for ECOMP logging, missing fields: %s, original message: %s";
+
+ LoggerBase(ILogFieldsHandler ecompLogFieldsHandler, Marker marker, Logger logger) {
+ this.ecompLogFieldsHandler = ecompLogFieldsHandler;
+ this.myMarker = marker;
+ this.myLogger = logger;
+ setKeyRequestIdIfNotSetYet();
+ }
+
+ public static String generateKeyRequestId() {
+ return UUID.randomUUID().toString();
+ }
+
+ public static String getRequestId(HttpServletRequest httpRequest) {
+ String onapRequestId = httpRequest.getHeader(ONAPLogConstants.Headers.REQUEST_ID);
+ 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());
+ }
+
+ 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);
+ }
+
+ protected void setKeyRequestIdIfNotSetYet() {
+ if (StringUtils.isEmpty(ecompLogFieldsHandler.getKeyRequestId())) {
+ setKeyRequestId(LoggingThreadLocalsHolder.getUuid());
+ }
+ }
+
+ 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.text()),
+ String.format(missingLogFieldsMsg, filedNameThatHasNotBeenInitialized, originMsg));
+ }
+ }
+
+ @VisibleForTesting
+ String checkMandatoryFieldsExistInMDC() {
+ // this method returns a String of uninitialised fields
+ StringBuilder missingFields = new StringBuilder();
+ getMandatoryFields().forEach(field -> {
+ if (ecompLogFieldsHandler.isMDCParamEmpty(field)) {
+ missingFields.append(field).append(" ");
+ }
+ });
+ return missingFields.toString();
+ }
+
+ public abstract List<String> getMandatoryFields();
+
+ protected String convertExceptionStackToString(Exception ex) {
+ StringBuilder stackTrack = new StringBuilder();
+ Arrays.asList(ex.getStackTrace()).forEach(item -> stackTrack.append(item.toString()).append("\n"));
+ return stackTrack.toString();
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message) {
+ log(logLevel, message, (Object) null);
+ }
+
+ @Override
+ public void log(Marker marker, LogLevel logLevel, String message) {
+ log(marker, logLevel, message, (Object) null);
+ }
+
+ @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
+ myLogger.error(myMarker, message, params);
+ break;
+ case WARN:
+ myLogger.warn(myMarker, message, params);
+ break;
+ case INFO:
+ myLogger.info(myMarker, message, params);
+ break;
+ case DEBUG:
+ myLogger.debug(myMarker, message, params);
+ break;
+ case TRACE:
+ myLogger.trace(myMarker, message, params);
+ break;
+ default:
+ break;
+ }
+ }
+
+ @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
+ myLogger.error(myMarker, createErrorMessage(message, throwable));
+ break;
+ case WARN:
+ myLogger.warn(myMarker, createErrorMessage(message, throwable));
+ break;
+ case INFO:
+ myLogger.info(myMarker, createErrorMessage(message, throwable));
+ break;
+ case DEBUG:
+ myLogger.debug(myMarker, message, throwable);
+ break;
+ case TRACE:
+ myLogger.trace(myMarker, message, throwable);
+ break;
+ default:
+ break;
+ }
+ }
+
+ @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
+ myLogger.error(marker, message, params);
+ break;
+ case WARN:
+ myLogger.warn(marker, message, params);
+ break;
+ case INFO:
+ myLogger.info(marker, message, params);
+ break;
+ case DEBUG:
+ myLogger.debug(marker, message, params);
+ break;
+ case TRACE:
+ myLogger.trace(marker, message, params);
+ break;
+ default:
+ break;
+ }
+ }
+
+ protected String createErrorMessage(String message, Throwable throwable) {
+ return String.format("%s: %s", message, throwable.getLocalizedMessage());
+ }
+
+
+ @Override
+ public ILogger clear() {
+ ecompLogFieldsHandler.clear();
+ return this;
+ }
+
+ @Override
+ public ILogger setKeyRequestId(String keyRequestId) {
+ ecompLogFieldsHandler.setKeyRequestId(keyRequestId);
+ 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/LoggerDebug.java b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerDebug.java
new file mode 100644
index 0000000000..dc8c4b4c16
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerDebug.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.LogMarkers;
+import org.slf4j.Logger;
+import org.slf4j.MarkerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class LoggerDebug extends LoggerBase {
+
+ private static List<String> mandatoryFields = new ArrayList<>(Arrays.asList(ONAPLogConstants.MDCs.REQUEST_ID));
+
+ LoggerDebug(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
+ super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.DEBUG_MARKER.text()), logger);
+ }
+
+ @Override
+ public LoggerDebug clear() {
+ //nothing to clean up
+ return this;
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message, Object...params){
+ setKeyRequestIdIfNotSetYet();
+ super.log(logLevel, message, params);
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message, Throwable throwable){
+ setKeyRequestIdIfNotSetYet();
+ super.log(logLevel, message, throwable);
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message){
+ setKeyRequestIdIfNotSetYet();
+ super.log(logLevel, message);
+ }
+
+ @Override
+ public LoggerDebug startTimer() {
+ return this;
+ }
+
+ @Override
+ public List<String> getMandatoryFields() {
+ return mandatoryFields;
+ }
+}
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
new file mode 100644
index 0000000000..a38f16df98
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerError.java
@@ -0,0 +1,163 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.api.LogConfigurationConstants;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+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.openecomp.sdc.common.log.enums.LogMarkers;
+import org.slf4j.Logger;
+import org.slf4j.MarkerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class LoggerError extends LoggerBase {
+ private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
+ ONAPLogConstants.MDCs.REQUEST_ID,
+ ONAPLogConstants.MDCs.SERVICE_NAME,
+ LogConfigurationConstants.MDC_ERROR_CATEGORY,
+ LogConfigurationConstants.MDC_ERROR_CODE));
+
+ public static final String defaultServiceName = "SDC catalog";
+
+ LoggerError(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
+ super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.ERROR_MARKER.text()), logger);
+ }
+
+ @Override
+ public List<String> getMandatoryFields() {
+ return Collections.unmodifiableList(mandatoryFields);
+ }
+
+ @Override
+ public LoggerError setKeyRequestId(String keyRequestId) {
+ return (LoggerError) super.setKeyRequestId(keyRequestId);
+ }
+
+ @Override
+ public LoggerError startTimer() {
+ return this;
+ }
+
+ @Override
+ public LoggerError clear() {
+ ecompLogFieldsHandler.removeErrorCategory();
+ ecompLogFieldsHandler.removeErrorDescription();
+ ecompLogFieldsHandler.removeErrorCode();
+ return this;
+ }
+
+ 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());
+ super.log(logLevel, description, params);
+ }
+
+ 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) {
+ log(convertFromSeverityErrorLevel(errorSeverity), errorCodeEnum, serviceName, targetEntity, message, 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) {
+ log(logLevel, errorCodeEnum, serviceName, message);
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message, Object...params) {
+ log(logLevel, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, defaultServiceName, (String)null, message, params);
+ }
+
+ public void log(LogLevel logLevel, String message, Throwable throwable) {
+ log(logLevel, createErrorMessage(message, throwable));
+ }
+
+ public void log(LogLevel logLevel, String message) {
+ log(logLevel, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, defaultServiceName, (String)null, message);
+ }
+
+ public void logInfo(LogLevel logLevel, String message, Object... params) {
+ log(logLevel, EcompLoggerErrorCode.SUCCESS, defaultServiceName, (String)null, message, params);
+ }
+
+ private LogLevel convertFromSeverityErrorLevel(EcompErrorSeverity severityLevel) {
+ switch(severityLevel) {
+ case INFO:
+ return LogLevel.INFO;
+ case FATAL:
+ return LogLevel.FATAL;
+ case ERROR:
+ return LogLevel.ERROR;
+ case WARN:
+ return LogLevel.WARN;
+ }
+ 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
new file mode 100644
index 0000000000..59e2777966
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerFactory.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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
+ */
+public class LoggerFactory {
+
+ private LoggerFactory() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T, V> V getLogger(Class<T> type, Logger logger) {
+
+ if (type.getName().equals(LoggerAudit.class.getName())) {
+ return (V) new LoggerAudit(new LogFieldsMdcHandler(), logger);
+ }
+
+ if (type.getName().equals(LoggerDebug.class.getName())) {
+ return (V) new LoggerDebug(new LogFieldsMdcHandler(), logger);
+ }
+
+ if (type.getName().equals(LoggerMetric.class.getName())) {
+ return (V) new LoggerMetric(new LogFieldsMdcHandler(), logger);
+ }
+
+ if (type.getName().equals(LoggerError.class.getName())) {
+ return (V) new LoggerError(new LogFieldsMdcHandler(), logger);
+ }
+
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T, V> V getMdcLogger(Class<T> type, Logger logger) {
+
+ if (type.getName().equals(LoggerAudit.class.getName())) {
+ return (V) new LoggerAudit(LogFieldsMdcHandler.getInstance(), logger);
+ }
+
+ if (type.getName().equals(LoggerDebug.class.getName())) {
+ return (V) new LoggerDebug(LogFieldsMdcHandler.getInstance(), logger);
+ }
+
+ if (type.getName().equals(LoggerMetric.class.getName())) {
+ return (V) new LoggerMetric(LogFieldsMdcHandler.getInstance(), logger);
+ }
+
+ if (type.getName().equals(LoggerError.class.getName())) {
+ return (V) new LoggerError(LogFieldsMdcHandler.getInstance(), logger);
+ }
+
+ if (type.getName().equals(LoggerSupportability.class.getName())) {
+ 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
new file mode 100644
index 0000000000..3dbcf1dde3
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerMetric.java
@@ -0,0 +1,193 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.LogMarkers;
+import org.openecomp.sdc.common.log.enums.Severity;
+import org.slf4j.Logger;
+import org.slf4j.MarkerFactory;
+
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.*;
+import static org.openecomp.sdc.common.log.api.LogConfigurationConstants.*;
+
+
+public class LoggerMetric extends LoggerBase {
+ private static List<String> mandatoryFields = new ArrayList<>(Arrays.asList(
+ INVOKE_TIMESTAMP,
+ MDC_END_TIMESTAMP,
+ REQUEST_ID,
+ SERVICE_NAME,
+ PARTNER_NAME,
+ RESPONSE_CODE,
+ MDC_SERVICE_INSTANCE_ID,
+ RESPONSE_DESCRIPTION,
+ MDC_ELAPSED_TIME,
+ TARGET_ENTITY,
+ MDC_SERVER_IP_ADDRESS,
+ SERVER_FQDN));
+
+ private static List<String> optionalFields = new ArrayList<>(Arrays.asList(
+ MDC_TARGET_VIRTUAL_ENTITY,
+ TARGET_ENTITY,
+ TARGET_SERVICE_NAME,
+ RESPONSE_STATUS_CODE,
+ INSTANCE_UUID,
+ RESPONSE_SEVERITY,
+ MDC_REMOTE_HOST,
+ CLIENT_IP_ADDRESS,
+ MDC_CLASS_NAME,
+ MDC_PROCESS_KEY,
+ MDC_OPT_FIELD1,
+ MDC_OPT_FIELD2,
+ MDC_OPT_FIELD3,
+ MDC_OPT_FIELD4));
+
+ LoggerMetric(ILogFieldsHandler ecompMdcWrapper, Logger logger) {
+ super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.METRIC_MARKER.text()), logger);
+ //put the remote host and FQDN values from another thread if they are set
+ ecompMdcWrapper.setServerIPAddressInternally();
+ ecompMdcWrapper.setServerFQDNInternally();
+ }
+
+ public void log(Response.StatusType statusInfo,
+ String className,
+ LogLevel logLevel,
+ Severity securityLevel,
+ String message) {
+ log(statusInfo,className, logLevel, securityLevel, message);
+ }
+
+ @Override
+ public void log(LogLevel logLevel, String message) {
+ setKeyRequestIdIfNotSetYet();
+ log(logLevel, message, (Object) null);
+ }
+
+ @Override
+ public LoggerMetric startTimer() {
+ clear();
+ ecompLogFieldsHandler.startMetricTimer();
+ return this;
+ }
+
+ public LoggerMetric stopTimer() {
+ ecompLogFieldsHandler.stopMetricTimer();
+ return this;
+ }
+
+ @Override
+ public LoggerMetric setKeyRequestId(String keyRequestId) {
+ return (LoggerMetric) super.setKeyRequestId(keyRequestId);
+ }
+
+ @Override
+ public List<String> getMandatoryFields() {
+ return mandatoryFields;
+ }
+
+ @Override
+ public LoggerMetric clear() {
+ ecompLogFieldsHandler.removeTargetEntity();
+ ecompLogFieldsHandler.removeTargetServiceName();
+ ecompLogFieldsHandler.removeResponseCode();
+ ecompLogFieldsHandler.removeResponseDesc();
+ ecompLogFieldsHandler.removeStatusCode();
+ return this;
+ }
+
+
+ public LoggerMetric setInstanceUUID(String instanceUUID) {
+ ecompLogFieldsHandler.setInstanceUUID(instanceUUID);
+ return this;
+ }
+
+
+ public LoggerMetric setOutgoingInvocationId(String out_invocationId) {
+ ecompLogFieldsHandler.setOutgoingInvocationId(out_invocationId);
+ return this;
+ }
+
+ public LoggerMetric setRemoteHost(String remoteHost) {
+ ecompLogFieldsHandler.setRemoteHost(remoteHost);
+ return this;
+ }
+
+ public LoggerMetric setServiceName(String serviceName) {
+ ecompLogFieldsHandler.setServiceName(serviceName);
+ return this;
+ }
+
+ public LoggerMetric setStatusCode(String statusCode) {
+ ecompLogFieldsHandler.setStatusCode(statusCode);
+ return this;
+ }
+
+ public LoggerMetric setPartnerName(String partnerName) {
+ ecompLogFieldsHandler.setPartnerName(partnerName);
+ return this;
+ }
+
+ public LoggerMetric setResponseCode(int responseCode) {
+ ecompLogFieldsHandler.setResponseCode(responseCode);
+ return this;
+ }
+
+ public LoggerMetric setResponseDesc(String responseDesc) {
+ ecompLogFieldsHandler.setResponseDesc(responseDesc);
+ return this;
+ }
+
+ public LoggerMetric setOptServiceInstanceId(String serviceInstanceId) {
+ ecompLogFieldsHandler.setServiceInstanceId(serviceInstanceId);
+ return this;
+ }
+
+ public LoggerMetric setOptClassName(String className) {
+ ecompLogFieldsHandler.setClassName(className);
+ return this;
+ }
+
+ public LoggerMetric setTargetEntity(String targetEntity) {
+ ecompLogFieldsHandler.setTargetEntity(targetEntity);
+ return this;
+ }
+
+ public LoggerMetric setTargetServiceName(String targetServiceName) {
+ ecompLogFieldsHandler.setTargetServiceName(targetServiceName);
+ return this;
+ }
+
+ public LoggerMetric setTargetVirtualEntity(String targetVirtualEntity) {
+ 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
new file mode 100644
index 0000000000..849add3625
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/elements/LoggerSupportability.java
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.elements;
+
+import org.openecomp.sdc.common.log.api.LogConfigurationConstants;
+import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.LogMarkers;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.slf4j.Logger;
+import org.slf4j.MarkerFactory;
+
+import java.util.*;
+
+public class LoggerSupportability extends LoggerBase {
+
+ public LoggerSupportability(ILogFieldsHandler ecompLogFieldsHandler, Logger logger) {
+ super(ecompLogFieldsHandler, MarkerFactory.getMarker(LogMarkers.SUPPORTABILITY_MARKER.text()),
+ logger);
+ }
+
+ public static LoggerSupportability getLogger(String 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) {
+ fillFieldsBeforeLogging(action,componentMetaData,statusCode);
+ super.log(LogLevel.INFO,message, params);
+ }
+
+ public void log(LoggerSupportabilityActions action, StatusCode statusCode, String message, Object...params) {
+ log(action, null, statusCode, message, params);
+ }
+
+ private static List<String> mandatoryFields = new ArrayList<>(Arrays.asList(
+ LogConfigurationConstants.MDC_SUPPORTABLITY_ACTION,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_UUID,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_VERSION,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_NAME,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_UUID,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_VERSION,
+ LogConfigurationConstants.MDC_SUPPORTABLITY_STATUS_CODE));
+
+ private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String,String> componentMetaData,StatusCode statusCode) {
+ clear();
+ if (componentMetaData!=null){
+ ecompLogFieldsHandler.setSupportablityCsarUUID(componentMetaData.get(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_UUID));
+ ecompLogFieldsHandler.setSupportablityCsarVersion(componentMetaData.get(LogConfigurationConstants.MDC_SUPPORTABLITY_CSAR_VERSION));
+ ecompLogFieldsHandler.setSupportablityComponentName(componentMetaData.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_NAME));
+ ecompLogFieldsHandler.setSupportablityComponentUUID(componentMetaData.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_UUID));
+ ecompLogFieldsHandler.setSupportablityComponentVersion(componentMetaData.get(LogConfigurationConstants.MDC_SUPPORTABLITY_COMPONENT_VERSION));
+ }
+ ecompLogFieldsHandler.setSupportablityAction(action.getName());
+ ecompLogFieldsHandler.setSupportablityStatusCode(statusCode.getStatusCodeEnum());
+ }
+
+ @Override
+ public LoggerSupportability clear(){
+ LogFieldsMdcHandler.getInstance().removeSupportablityAction();
+ LogFieldsMdcHandler.getInstance().removeSupportablityCsarUUID();
+ LogFieldsMdcHandler.getInstance().removeSupportablityCsarVersion();
+ LogFieldsMdcHandler.getInstance().removeSupportablityComponentName();
+ LogFieldsMdcHandler.getInstance().removeSupportablityComponentUUID();
+ LogFieldsMdcHandler.getInstance().removeSupportablityComponentVersion();
+ LogFieldsMdcHandler.getInstance().removeSupportablityStatusCode();
+ return this;
+ }
+
+
+ @Override
+ public List<String> getMandatoryFields() {
+ return Collections.unmodifiableList(mandatoryFields);
+ }
+
+ @Override
+ 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
new file mode 100644
index 0000000000..34606dcebd
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/ConstantsLogging.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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";
+ public static final String X_ECOMP_REQUEST_ID_HEADER = "X-ECOMP-RequestID";
+ public static final String X_TRANSACTION_ID_HEADER = "X-TransactionId";
+ 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
new file mode 100644
index 0000000000..4d21d8c8c6
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompErrorSeverity.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+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
new file mode 100644
index 0000000000..db174b4096
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/EcompLoggerErrorCode.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+/**
+ * Created by dd4296 on 12/26/2017.
+ */
+public enum EcompLoggerErrorCode {
+ SUCCESS(0),
+ PERMISSION_ERROR(100),
+ AVAILABILITY_TIMEOUTS_ERROR(200),
+ DATA_ERROR(300),
+ SCHEMA_ERROR(400),
+ BUSINESS_PROCESS_ERROR(500),
+ UNKNOWN_ERROR(900);
+
+ private int errorCode;
+
+ EcompLoggerErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public static EcompLoggerErrorCode getByValue(String ecompErrorCode) {
+ String errorPrefix = parseCode(ecompErrorCode);
+ Optional<EcompLoggerErrorCode> optionalCode = Arrays.stream(values()).filter(v->isCode(v, errorPrefix)).findFirst();
+ return optionalCode.orElse(UNKNOWN_ERROR);
+ }
+
+ private static boolean isCode(EcompLoggerErrorCode ecompLoggerErrorCode, String errorPrefix) {
+ return String.valueOf(ecompLoggerErrorCode.getErrorCode()).contains(errorPrefix);
+ }
+
+ private static String parseCode(String errorCode) {
+ try {
+ return errorCode.substring("E_".length(), 3);
+ } catch (StringIndexOutOfBoundsException ex) {
+ 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
new file mode 100644
index 0000000000..aaee7512bd
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogLevel.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.common.log.enums;
+
+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
new file mode 100644
index 0000000000..7b12ded745
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LogMarkers.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+public enum LogMarkers {
+ DEBUG_MARKER("DEBUG_MARKER"),
+ ERROR_MARKER("ERROR_MARKER"),
+ METRIC_MARKER("METRICS"),
+ SUPPORTABILITY_MARKER("SUPPORTABILITY_MARKER");
+
+ private String text;
+
+ LogMarkers (String text){
+ this.text = text;
+ }
+
+ public String text(){
+ return 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
new file mode 100644
index 0000000000..d831700dec
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/LoggerSupportabilityActions.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+public enum LoggerSupportabilityActions {
+ IMPORT_CSAR("CREATE RESOURCE FROM CSAR"),
+ CREATE_RESOURCE_FROM_YAML("CREATE RESOURCE FROM YAML"),
+ CREATE_RI_AND_RELATIONS("CREATE RI AND RELATIONS"),
+ CREATE_NODES_AND_CVFCS("ADD NODES AND CVFCS"),
+ CREATE_ARTIFACTS("ADD ARTIFACTS"),
+ CREATE_SERVICE("CREATE SERVICE"),
+ CREATE_RESOURCE("CREATE RESOURCE"),
+ CREATE_PROPERTIES("ADD PROPERTIES"),
+ CREATE_INPUTS("ADD INPUTS"),
+ CREATE_POLICIES("ADD POLICIES"),
+ CREATE_RELATIONS("ADD RELATIONS"),
+ CREATE_CAPABILITY_REQUIREMENTS("CREATE CAPABILITY REQUIREMENTS"),
+ MERGE("MERGE"),
+ PROPERTY_ASSIGNMENT("PROPERTY ASSIGNMENT"),
+ CREATE_INSTANCE("CREATE INSTANCE"),
+ CREATE_RELATION("ADD RELATION"),
+ CREATE_GROUP_POLICY("ADD GROUP POLICY"),
+ CREATE_GROUPS("ADD GROUPS"),
+ UPDATE_PROPERTY_IN_GROUP_POLICY("UPDATE PROPERTY IN GROUP POLICY"),
+ UPDATE_CAPABILITY("UPDATE CAPABILITY"),
+ PROPERTY("ADD PROPERTY"),
+ UPLOAD_DOWNLOAD_ARTIFACT("UPLOAD/DOWNLOAD ARTIFACT"),
+ LIFECYCLE("LIFECYCLE"),
+ DISTRIBUTION("DISTRIBUTION"),
+ UPDATE_CATALOG("UPDATE CATALOG"),
+ ARCHIVE("ARCHIVE"),
+ TENANT_ISOLATION("TENANT ISOLATION"),
+ DOWNLOAD_ARTIFACTS("DOWNLOAD ARTIFACTS"),
+ UPDATE_HEAT("UPDATE HEAT"),
+ PARAMETERS("PARAMETERS"),
+ CHANGELIFECYCLESTATE("CHANGE LIFECYCLE STATE"),
+ VALIDATE_NAME("VALIDATE COMPONENT NAME"),
+ DELETE_COMPONENT_INSTANCE_ARTIFACT("DELETE COMPONENT INSTANCE ARTIFACT"),
+ DELETE_SERVICE("DELETE SERVICE"),
+ DELETE_RESOURCE("DELETE RESOURCE"),
+ UPDATE_RESOURCE("UPDATE RESOURCE"),
+ UPDATE_COMPONENT_INSTANCE("UPDATE COMPONENT INSTANCE"),
+ DELETE_COMPONENT_INSTANCE("DELETE COMPONENT INSTANCE"),
+ UPDATE_PROPERTIES("UPDATE PROPERTIES"),
+ RESTORE_FROM_ARCHIVE("RESTORE FROM ARCHIVE"),
+ UPDATE_INPUTS("UPDATE INPUTS"),
+ DELETE_INPUTS("DELETE INPUTS"),
+ ASSOCIATE_RI_TO_RI("ASSOCIATE RI TO RI"),
+ UN_ASSOCIATE_RI_TO_RI("UN ASSOCIATE RI TO RI"),
+ UPDATE_ARTIFACT("UPDATE ARTIFACT"),
+ GENERATE_CSAR("GENERATE CSAR"),
+ GENERATE_TOSCA("GENERATE TOSCA"),
+ UPDATE_GROUP_MEMBERS("UPDATE GROUP MEMBERS"),
+ UPDATE_INSTANCE_CAPABILITY_PROPERTY("UPDATE INSTANCE CAPABILITY PROPERTY"),
+ UPDATE_POLICY_TARGET("UPDATE POLICY TARGET"),
+ UPDATE_POLICIES_PROPERTIES("UPDATE POLICIES PROPERTIES");
+ private String name;
+
+ LoggerSupportabilityActions(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return 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
new file mode 100644
index 0000000000..0e90d57c8e
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/Severity.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+public enum Severity {
+ OK(0),
+ WARNING(1),
+ CRITICAL(2),
+ DOWN(3),
+ UNREACHABLE(4);
+
+ int severityType;
+
+ Severity(int serveryType) {
+ this.severityType = serveryType;
+ }
+
+ public int getSeverityType() {
+ return 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
new file mode 100644
index 0000000000..4ed65df97b
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/enums/StatusCode.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.enums;
+
+public enum StatusCode {
+ ERROR("ERROR"),
+ STARTED("STARTED"),
+ COMPLETE("COMPLETE"),
+ INPROGRESS("INPROGRESS");
+
+ String statusCode;
+
+ StatusCode(String statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getStatusCodeEnum() {
+ return 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
new file mode 100644
index 0000000000..9c90529d22
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/EcompLogErrorCode.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.utils;
+
+public enum EcompLogErrorCode {
+ E_399("Internal Invalid Object. Description: %s"),
+ E_210("Connection problem towards U-EB server. Reason: %s");
+
+
+ String description;
+
+ EcompLogErrorCode(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = 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
new file mode 100644
index 0000000000..3d7a16b846
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/utils/LoggingThreadLocalsHolder.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.utils;
+
+
+public class LoggingThreadLocalsHolder {
+
+ private 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();
+ }
+
+
+
+ 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
new file mode 100644
index 0000000000..9c2bfec126
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/Logger.java
@@ -0,0 +1,656 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.wrappers;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.openecomp.sdc.common.log.elements.*;
+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
+ */
+public class Logger implements org.slf4j.Logger {
+ private final LoggerDebug debug;
+ private final LoggerError error;
+ private final LoggerMetric metric;
+ private final org.slf4j.Logger logger;
+
+ @VisibleForTesting
+ public Logger(org.slf4j.Logger logger) {
+ this.logger = 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) {
+ this(org.slf4j.LoggerFactory.getLogger(className));
+ }
+
+ public static Logger getLogger(String className) {
+ return new Logger(className);
+ }
+
+ public static Logger getLogger(Class<?> clazz) {
+ return new Logger(clazz.getName());
+ }
+
+
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ @Override
+ public String getName() {
+ return logger.getName();
+ }
+
+ public boolean isTraceEnabled() {
+ return logger.isTraceEnabled();
+ }
+
+ public boolean isErrorEnabled() { return logger.isErrorEnabled(); }
+
+ public boolean isWarnEnabled() { return logger.isWarnEnabled(); }
+
+ @Override
+ @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ public void warn(String msg) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, msg);
+ }
+ }
+
+ @Override
+ @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(); }
+
+ @Override
+ public void info(String msg) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg);
+ }
+ }
+
+ @Override
+ public void info(String msg, Object o) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, o);
+ }
+ }
+
+ @Override
+ public void info(String msg, Object o, Object o1) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, o, o1);
+ }
+ }
+
+ public void debug(String msg, Object... params) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, params);
+ }
+ }
+
+ public void metric(String msg, Object... params) {
+ metric.log(LogLevel.INFO, msg, params);
+ }
+
+ public void invoke(String remoteHost, String targetEntity, String targetServiceName, String serviceName, String msg, Object... params) {
+
+ String invocationId = UUID.randomUUID().toString();
+ String requestID = UUID.randomUUID().toString();
+
+ metric.startTimer()
+ .stopTimer()
+ .setRemoteHost(remoteHost)
+ .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();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ metric.log(ONAPLogConstants.Markers.INVOKE_RETURN, LogLevel.INFO, msg, params);
+ }
+
+ public void invokeSynchronous(String msg, Object... params) {
+ metric.log(ONAPLogConstants.Markers.INVOKE_SYNCHRONOUS, LogLevel.INFO, msg, params);
+ }
+
+ @Override
+ public void debug(String msg, Throwable throwable) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, throwable);
+ }
+ }
+
+ @Override
+ public boolean isDebugEnabled(Marker marker) {
+ return false;
+ }
+
+ @Override
+ public void debug(Marker marker, String msg) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg);
+ }
+ }
+
+ @Override
+ public void debug(Marker marker, String msg, Object o) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, o);
+ }
+ }
+
+ @Override
+ public void debug(Marker marker, String msg, Object o, Object o1) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, o, o1);
+ }
+ }
+
+ @Override
+ public void debug(Marker marker, String msg, Object... objects) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, objects);
+ }
+ }
+
+ @Override
+ public void debug(Marker marker, String msg, Throwable throwable) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, throwable);
+ }
+ }
+
+ public void debug(String message) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, message);
+ }
+ }
+
+ @Override
+ public void debug(String msg, Object o) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, o);
+ }
+ }
+
+ @Override
+ public void debug(String msg, Object o, Object o1) {
+ if (isDebugEnabled()) {
+ debug.log(LogLevel.DEBUG, msg, o, o1);
+ }
+ }
+
+ public void trace(String message, Object... params) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, message, params);
+ }
+ }
+
+ @Override
+ public void trace(String msg, Throwable throwable) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, throwable);
+ }
+ }
+
+ @Override
+ public boolean isTraceEnabled(Marker marker) {
+ return false;
+ }
+
+ @Override
+ public void trace(Marker marker, String msg) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg);
+ }
+ }
+
+ @Override
+ public void trace(Marker marker, String msg, Object o) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, o);
+ }
+ }
+
+ @Override
+ public void trace(Marker marker, String msg, Object o, Object o1) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, o, o1);
+ }
+ }
+
+ @Override
+ public void trace(Marker marker, String msg, Object... objects) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, objects);
+ }
+ }
+
+ @Override
+ public void trace(Marker marker, String msg, Throwable throwable) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, throwable);
+ }
+ }
+
+ public void trace(String msg) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg);
+ }
+ }
+
+ @Override
+ public void trace(String msg, Object o) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, o);
+ }
+ }
+
+ @Override
+ public void trace(String msg, Object o, Object o1) {
+ if (isTraceEnabled()) {
+ debug.log(LogLevel.TRACE, msg, o, o1);
+ }
+ }
+
+ public void info(String msg, Object... params) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, params);
+ }
+ }
+
+ @Override
+ public void info(String msg, Throwable throwable) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, throwable);
+ }
+ }
+
+ @Override
+ public boolean isInfoEnabled(Marker marker) {
+ return false;
+ }
+
+ @Override
+ public void info(Marker marker, String msg) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg);
+ }
+ }
+
+ @Override
+ public void info(Marker marker, String msg, Object o) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, o);
+ }
+ }
+
+ @Override
+ public void info(Marker marker, String msg, Object o, Object o1) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, o, o1);
+ }
+ }
+
+ @Override
+ public void info(Marker marker, String msg, Object... objects) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, objects);
+ }
+ }
+
+ @Override
+ public void info(Marker marker, String msg, Throwable throwable) {
+ if (isInfoEnabled()) {
+ debug.log(LogLevel.INFO, msg, throwable);
+ }
+ }
+
+ @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)} **/
+ public void warn(String msg, Object o, Object o1) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, msg, o, o1);
+ }
+ }
+
+ @Override
+ @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ public void warn(String msg, Throwable throwable) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, msg, throwable);
+ }
+ }
+
+ @Override
+ public boolean isWarnEnabled(Marker marker) {
+ return false;
+ }
+
+ @Override
+ @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
+ public void warn(Marker marker, String msg) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, msg);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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){
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, msg, params);
+ }
+ }
+
+ @Override
+ @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ public void error(String msg, Throwable throwable) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, msg, throwable);
+ }
+ }
+
+ @Override
+ public boolean isErrorEnabled(Marker marker) {
+ return false;
+ }
+
+ @Override
+ @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ public void error(Marker marker, String msg) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, msg);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ @Override
+ @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){
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, msg);
+ }
+ }
+
+ @Override
+ @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
+ public void error(String msg, Object o) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, msg, o);
+ }
+ }
+
+ @Override
+ @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);
+ }
+ }
+
+ /**
+ * 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 errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
+ */
+ 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);
+ }
+ }
+
+ /**
+ * 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 errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
+ */
+ @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, ErrorLogOptionalData, String, Object...)} **/
+ public void error(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ String targetEntity,
+ String errorDescription, Object...params) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
+ }
+ }
+
+ /* Writes out ERROR logging level message to the application error LOG
+ * @param errorCodeEnum code representing the error condition
+ * @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);
+ }
+
+ /**
+ * 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 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
+ */
+ public void error(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ ErrorLogOptionalData errorLogOptionalData,
+ String errorDescription,
+ Object...params) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.ERROR, errorCodeEnum, serviceName, errorLogOptionalData, errorDescription, params);
+ }
+ }
+
+ /**
+ * 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 errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
+ */
+ public void warn(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ String targetEntity,
+ String errorDescription, Object...params) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
+ }
+ }
+
+ /**
+ * 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 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
+ */
+ public void warn(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ ErrorLogOptionalData errorLogOptionalData,
+ String description, Object...params) {
+ if (isWarnEnabled()) {
+ error.log(LogLevel.WARN, errorCodeEnum, serviceName, errorLogOptionalData, description, params);
+ }
+ }
+
+ /**
+ * 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 errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
+ */
+ public void warn(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ String errorDescription, Object...params) {
+ if (isWarnEnabled()) {
+ 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 errorDescription a human readable description of the error condition
+ * @param params optional parameters of a given error description
+ */
+ public void fatal(EcompLoggerErrorCode errorCodeEnum,
+ String serviceName,
+ String targetEntity,
+ String errorDescription, Object...params) {
+ if (isErrorEnabled()) {
+ error.log(LogLevel.FATAL, errorCodeEnum, serviceName, targetEntity, 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 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
+ */
+ 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
new file mode 100644
index 0000000000..b2db66ed00
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcAudit.java
@@ -0,0 +1,177 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.wrappers;
+
+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.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.Severity;
+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
+ */
+public class LoggerSdcAudit extends LoggerSdcUtilBase {
+
+ private static String AUDIT_ON = "auditOn";
+ private String className;
+ private final LoggerAudit ecompLoggerAudit;
+
+ public LoggerSdcAudit(Class<?> clazz) {
+ this.className = clazz.getName();
+ ecompLoggerAudit = LoggerFactory.getMdcLogger(LoggerAudit.class, org.slf4j.LoggerFactory.getLogger(clazz));
+ }
+
+ 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());
+ MDC.put(AUDIT_ON, "true");
+ }
+
+ public void startAuditFetchLog(String partnerName, String 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(){
+ ecompLoggerAudit.clear();
+ }
+
+ 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) {
+ log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
+ }
+ finally {
+ MDC.put(AUDIT_ON,"false");
+ }
+ }
+
+ 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) {
+ log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
+ }
+ finally {
+ MDC.put(AUDIT_ON,"false");
+ }
+ }
+
+ 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) {
+ log.warn("Failed to write to Audit Log. Original Message: {}", message, e);
+ }
+ 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
new file mode 100644
index 0000000000..cec429a000
--- /dev/null
+++ b/common-app-logging/src/main/java/org/openecomp/sdc/common/log/wrappers/LoggerSdcUtilBase.java
@@ -0,0 +1,204 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.log.wrappers;
+
+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.*;
+
+public class LoggerSdcUtilBase {
+
+ protected static Logger log = LoggerFactory.getLogger(LoggerSdcUtilBase.class.getName());
+
+ 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("]","");
+ }
+
+
+
+ // 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;
+ }
+ if (isDataError(httpResponseCode)) {
+ return EcompLoggerErrorCode.DATA_ERROR;
+ }
+ if (isPermissionsError(httpResponseCode)) {
+ return EcompLoggerErrorCode.PERMISSION_ERROR;
+ }
+ if (isTimeoutOrAvailabilityError(httpResponseCode)) {
+ return EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR;
+ }
+ if (isBusinessProcessError(httpResponseCode)) {
+ return EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+ }
+ return EcompLoggerErrorCode.UNKNOWN_ERROR;
+ }
+
+ private boolean isTimeoutOrAvailabilityError(int httpResponseCode) {
+
+ switch (httpResponseCode) {
+ case HTTP_BAD_REQUEST:
+ case HTTP_UNAUTHORIZED:
+ case HTTP_NOT_FOUND:
+ case HTTP_CLIENT_TIMEOUT:
+ case HTTP_GONE:
+ return true;
+ default:
+ return false;
+ }
+
+ }
+
+ private boolean isPermissionsError(int httpResponseCode) {
+
+ switch (httpResponseCode) {
+ case HTTP_PAYMENT_REQUIRED:
+ case HTTP_FORBIDDEN:
+ case HTTP_BAD_METHOD:
+ case HTTP_PROXY_AUTH:
+ return true;
+ default: return false;
+ }
+ }
+
+ private boolean isDataError(int httpResponseCode) {
+
+ switch (httpResponseCode) {
+ case HTTP_NOT_ACCEPTABLE:
+ case HTTP_LENGTH_REQUIRED:
+ case HTTP_PRECON_FAILED:
+ case HTTP_REQ_TOO_LONG:
+ case HTTP_ENTITY_TOO_LARGE:
+ case HTTP_UNSUPPORTED_TYPE:
+ return true;
+ default: return false;
+ }
+ }
+
+ private boolean isSchemaError(int httpResponseCode) {
+ return HTTP_CONFLICT == httpResponseCode;
+ }
+
+ private boolean isSuccessError(int httpResponseCode) {
+ return httpResponseCode < 399;
+ }
+
+ private boolean isBusinessProcessError(int httpResponseCode) {
+ return httpResponseCode > 499;
+ }
+
+ 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)){
+ 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";
+ }
+
+ private String getUserIdFromUserAgent(String userAgent) {
+ if (userAgent != null && userAgent.length() > 0) {
+ 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;
+ }
+
+ private String getUserIdFromUrl(String url) {
+ if (url != null && url.toLowerCase().contains("user")) {
+ StringTokenizer st = new StringTokenizer(url, "/");
+ while (st.hasMoreElements()) {
+ if ("user".equalsIgnoreCase(st.nextToken())) {
+ return st.nextToken();
+ }
+ }
+ }
+ return null;
+ }
+
+ protected String getUrl(ContainerRequestContext requestContext) {
+ String url = "";
+
+ try {
+ if (requestContext.getUriInfo() != null && requestContext.getUriInfo().getRequestUri() != null) {
+ url = requestContext.getUriInfo().getRequestUri().toURL().toString();
+ }
+ } 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(), "/");
+ }
+
+ private boolean isFound(String value) {
+ return (StringUtils.isNotEmpty(value));
+ }
+} \ No newline at end of file