diff options
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog')
17 files changed, 1222 insertions, 0 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerAudit.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerAudit.java new file mode 100644 index 0000000000..e5f5fc99dd --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerAudit.java @@ -0,0 +1,184 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ALERT_SEVERITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_CLASS_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ELAPSED_TIME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_END_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_INSTANCE_UUID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_KEY_REQUEST_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD1; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD2; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD3; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD4; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PARTNER_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PROCESS_KEY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_REMOTE_HOST; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_DESC; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_FQDN; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_IP_ADDRESS; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_INSTANCE_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_STATUS_CODE; + +import org.openecomp.sdc.common.ecomplog.Enums.EcompLoggerErrorCode; +import org.openecomp.sdc.common.ecomplog.Enums.LogMarkers; +import org.openecomp.sdc.common.ecomplog.Enums.Severity; +import org.openecomp.sdc.common.ecomplog.Enums.StatusCode; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.slf4j.MDC; +import org.slf4j.MarkerFactory; + +public class EcompLoggerAudit extends EcompLoggerBase{ + private static EcompLoggerAudit instanceLoggerAudit = EcompLoggerFactory.getLogger(EcompLoggerAudit.class); + + EcompLoggerAudit(IEcompMdcWrapper ecompMdcWrapper) { + super (ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.AUDIT_MARKER.text())); + } + + public static EcompLoggerAudit getInstance() { + return instanceLoggerAudit; + } + + @Override + public EcompLoggerAudit startTimer() { + return (EcompLoggerAudit) super.startTimer(); + } + + public EcompLoggerAudit stopTimer() { + ecompMdcWrapper.stopTimer(); + return this; + } + + // automatic parameter this is optional + public EcompLoggerAudit setAutoServerFQDN(String serverFQDN) { + ecompMdcWrapper.setAutoServerFQDN(serverFQDN); + return this; + } + + // automatic parameter this is optional + public EcompLoggerAudit setAutoServerIPAddress(String serverIPAddress) { + ecompMdcWrapper.setAutoServerIPAddress(serverIPAddress); + return this; + } + + public EcompLoggerAudit setInstanceUUID(String instanceUUID) { + ecompMdcWrapper.setInstanceUUID(instanceUUID); + return this; + } + + public EcompLoggerAudit setOptClassName(String className) { + MDC.put("ClassName", className); + return this; + } + + public EcompLoggerAudit setOptProcessKey(String processKey) { + ecompMdcWrapper.setProcessKey(processKey); + return this; + } + + public EcompLoggerAudit setOptAlertSeverity(Severity alertSeverity) { + ecompMdcWrapper.setAlertSeverity(alertSeverity); + return this; + } + + // ecomplog optional parameter + public EcompLoggerAudit setOptCustomField1(String customField1) { + ecompMdcWrapper.setOptCustomField1(customField1); + return this; + } + + // ecomplog optional parameter + public EcompLoggerAudit setOptCustomField2(String customField2) { + ecompMdcWrapper.setOptCustomField2(customField2); + return this; + } + + // ecomplog optional parameter + public EcompLoggerAudit setOptCustomField3(String customField3) { + ecompMdcWrapper.setOptCustomField3(customField3); + return this; + } + + public EcompLoggerAudit setOptCustomField4(String customField4) { + ecompMdcWrapper.setOptCustomField4(customField4); + return this; + } + + @Override + public EcompLoggerAudit setKeyRequestId(String keyRequestId) { + return (EcompLoggerAudit) super.setKeyRequestId(keyRequestId); + } + + public EcompLoggerAudit setRemoteHost(String remoteHost) { + ecompMdcWrapper.setRemoteHost(remoteHost); + return this; + } + + public EcompLoggerAudit setServiceName(String serviceName) { + ecompMdcWrapper.setServiceName(serviceName); + return this; + } + + public EcompLoggerAudit setStatusCode(String statusCode) { + // status code is either success (COMPLETE) or failure (ERROR) of the request. + String respStatus = Integer.parseInt(statusCode) / 100 == 2 ? StatusCode.COMPLETE.getStatusCodeEnum() : StatusCode.ERROR.getStatusCodeEnum(); + ecompMdcWrapper.setStatusCode(respStatus); + return this; + } + + public EcompLoggerAudit setPartnerName(String partnerName) { + ecompMdcWrapper.setPartnerName(partnerName); + return this; + } + + public EcompLoggerAudit setResponseCode(EcompLoggerErrorCode responseCode) { + ecompMdcWrapper.setResponseCode(responseCode.getErrorCode()); + return this; + } + + public EcompLoggerAudit setResponseDesc(String responseDesc) { + ecompMdcWrapper.setResponseDesc(responseDesc); + return this; + } + + public EcompLoggerAudit setOptServiceInstanceId(String serviceInstanceId) { + ecompMdcWrapper.setServiceInstanceId(serviceInstanceId); + return this; + } + + @Override + public EcompLoggerAudit clear() { + return (EcompLoggerAudit) super.clear(); + } + + @Override + public void initializeMandatoryFields() { + + ecompMdcWrapper.setMandatoryField(MDC_BEGIN_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_END_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_KEY_REQUEST_ID); + ecompMdcWrapper.setMandatoryField(MDC_SERVICE_NAME); + ecompMdcWrapper.setMandatoryField(MDC_PARTNER_NAME); + ecompMdcWrapper.setMandatoryField(MDC_STATUS_CODE); + ecompMdcWrapper.setMandatoryField(MDC_RESPONSE_CODE); + ecompMdcWrapper.setMandatoryField(MDC_SERVICE_INSTANCE_ID); + ecompMdcWrapper.setMandatoryField(MDC_RESPONSE_DESC); + ecompMdcWrapper.setMandatoryField(MDC_ELAPSED_TIME); + + //Theoretically Optional, but practically Mandatory + ecompMdcWrapper.setMandatoryField(MDC_SERVER_IP_ADDRESS); + ecompMdcWrapper.setMandatoryField(MDC_SERVER_FQDN); + + ecompMdcWrapper.setOptionalField(MDC_INSTANCE_UUID); + ecompMdcWrapper.setOptionalField(MDC_ALERT_SEVERITY); + ecompMdcWrapper.setOptionalField(MDC_REMOTE_HOST); + ecompMdcWrapper.setOptionalField(MDC_CLASS_NAME); + ecompMdcWrapper.setOptionalField(MDC_PROCESS_KEY); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD1); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD2); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD3); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD4); + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerBase.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerBase.java new file mode 100644 index 0000000000..535e8a4204 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerBase.java @@ -0,0 +1,79 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_FQDN; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_IP_ADDRESS; + +import org.openecomp.sdc.common.ecomplog.Enums.LogLevel; +import org.openecomp.sdc.common.ecomplog.api.IEcompLogger; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.Marker; + + +/** + * Created by mm288v on 12/27/2017. + * This class holds the common behavior of all Loger-Typed classes. + * The Concrete loggers shoudl derive from this one. + */ +public abstract class EcompLoggerBase implements IEcompLogger{ + private static Logger myLogger = LoggerFactory.getLogger(IEcompLogger.class.getName()); + private Marker myMarker; + IEcompMdcWrapper ecompMdcWrapper; + + EcompLoggerBase(IEcompMdcWrapper ecompMdcWrapper, Marker marker) { + this.ecompMdcWrapper = ecompMdcWrapper; + initializeMandatoryFields(); + this.myMarker = marker; + } + + @Override + public void log(LogLevel errorLevel, String message) { + + ecompMdcWrapper.validateMandatoryFields(); + + if (this instanceof EcompLoggerAudit || this instanceof EcompLoggerMetric) { + MDC.put(MDC_SERVER_IP_ADDRESS, EcompMDCWrapper.getInstance().getHostAddress()); + MDC.put(MDC_SERVER_FQDN, EcompMDCWrapper.getInstance().getFqdn()); + } + + if (errorLevel.equals(LogLevel.ERROR)) { + myLogger.error(myMarker, message); + return; + } + + if (errorLevel.equals(LogLevel.WARN)) { + myLogger.warn(myMarker, message); + return; + } + + if (errorLevel.equals(LogLevel.INFO)) { + myLogger.info(myMarker, message); + return; + } + + if (errorLevel.equals(LogLevel.DEBUG)) { + myLogger.info(myMarker, message); + } + } + + @Override + public IEcompLogger clear() { + ecompMdcWrapper.clear(); + return this; + } + + @Override + public IEcompLogger startTimer() { + ecompMdcWrapper.startTimer(); + return this; + } + + @Override + public IEcompLogger setKeyRequestId(String keyRequestId) { + ecompMdcWrapper.setKeyRequestId(keyRequestId); + return this; + } + +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerDebug.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerDebug.java new file mode 100644 index 0000000000..aecb487e24 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerDebug.java @@ -0,0 +1,51 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_KEY_REQUEST_ID; + +import org.openecomp.sdc.common.ecomplog.Enums.LogLevel; +import org.openecomp.sdc.common.ecomplog.Enums.LogMarkers; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.slf4j.MarkerFactory; + +public class EcompLoggerDebug extends EcompLoggerBase { + + private static EcompLoggerDebug instanceLoggerDebug = EcompLoggerFactory.getLogger(EcompLoggerDebug.class); + + protected final String endOfRecordDelimiter = "|^\\n"; + + EcompLoggerDebug(IEcompMdcWrapper ecompMdcWrapper) { + super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.DEBUG_MARKER.text())); + } + + public static EcompLoggerDebug getInstance() { + return instanceLoggerDebug; + } + + @Override + public void log(LogLevel errorLevel, String message) { + String formattedMessage = String.format("%s%s", message, endOfRecordDelimiter); + super.log(errorLevel, formattedMessage); + } + + @Override + public void initializeMandatoryFields() { + ecompMdcWrapper.setMandatoryField(MDC_BEGIN_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_KEY_REQUEST_ID); + } + + @Override + public EcompLoggerDebug clear() { + return (EcompLoggerDebug) super.clear(); + } + + @Override + public EcompLoggerDebug startTimer() { + return (EcompLoggerDebug) super.startTimer(); + } + + @Override + public EcompLoggerDebug setKeyRequestId(String keyRequestId) { + return (EcompLoggerDebug) super.setKeyRequestId(keyRequestId); + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerError.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerError.java new file mode 100644 index 0000000000..92a495fda7 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerError.java @@ -0,0 +1,77 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ERROR_CATEGORY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ERROR_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ERROR_DESC; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_KEY_REQUEST_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PARTNER_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_ENTITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_SERVICE_NAME; + +import org.openecomp.sdc.common.ecomplog.Enums.EcompLoggerErrorCode; +import org.openecomp.sdc.common.ecomplog.Enums.LogMarkers; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.slf4j.MarkerFactory; + +public class EcompLoggerError extends EcompLoggerBase{ + private static EcompLoggerError instanceLoggerError = EcompLoggerFactory.getLogger(EcompLoggerError.class); + + EcompLoggerError(IEcompMdcWrapper ecompMdcWrapper) { + super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.ERROR_MARKER.text())); + } + + public static EcompLoggerError getInstance() { + return instanceLoggerError; + } + + @Override + public void initializeMandatoryFields() { + ecompMdcWrapper.setMandatoryField(MDC_BEGIN_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_KEY_REQUEST_ID); + ecompMdcWrapper.setMandatoryField(MDC_SERVICE_NAME); + ecompMdcWrapper.setMandatoryField(MDC_PARTNER_NAME); + ecompMdcWrapper.setMandatoryField(MDC_ERROR_CATEGORY); + ecompMdcWrapper.setMandatoryField(MDC_ERROR_CODE); + ecompMdcWrapper.setMandatoryField(MDC_ERROR_DESC); + + ecompMdcWrapper.setOptionalField(MDC_TARGET_ENTITY); + ecompMdcWrapper.setOptionalField(MDC_TARGET_SERVICE_NAME); + } + + @Override + public EcompLoggerError startTimer() { + return (EcompLoggerError) super.startTimer(); + } + + @Override + public EcompLoggerError setKeyRequestId(String keyRequestId) { + return (EcompLoggerError) super.setKeyRequestId(keyRequestId); + } + + public EcompLoggerError setServiceName(String serviceName) { + ecompMdcWrapper.setServiceName(serviceName); + return this; + } + + public EcompLoggerError setTargetEntity(String targetEntity) { + ecompMdcWrapper.setTargetEntity(targetEntity); + return this; + } + + public EcompLoggerError setErrorCode(EcompLoggerErrorCode errorCode) { + ecompMdcWrapper.setErrorCode(errorCode.getErrorCode()); + return this; + } + + public EcompLoggerError setErrorDescription(String errorDescription) { + ecompMdcWrapper.setErrorDescription(errorDescription); + return this; + } + + public EcompLoggerError clear() { + return (EcompLoggerError) super.clear(); + } + +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerFactory.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerFactory.java new file mode 100644 index 0000000000..2ea1280f48 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerFactory.java @@ -0,0 +1,34 @@ +package org.openecomp.sdc.common.ecomplog; + +/** + * Created by dd4296 on 12/26/2017. + * this factory helps decouple the classes for Stopwatch and EcompMDCWrapper from + * the EcompLogger classes + */ +public class EcompLoggerFactory { + + private EcompLoggerFactory() { + } + + @SuppressWarnings("unchecked") + static public <T, V> V getLogger(Class<T> type) { + + if (type.getName().equals(EcompLoggerAudit.class.getName())) { + return (V) new EcompLoggerAudit(new EcompMDCWrapper(new Stopwatch())); + } + + if (type.getName().equals(EcompLoggerDebug.class.getName())) { + return (V) new EcompLoggerDebug(new EcompMDCWrapper(new Stopwatch())); + } + + if (type.getName().equals(EcompLoggerMetric.class.getName())) { + return (V) new EcompLoggerMetric(new EcompMDCWrapper(new Stopwatch())); + } + + if (type.getName().equals(EcompLoggerError.class.getName())) { + return (V) new EcompLoggerError(new EcompMDCWrapper(new Stopwatch())); + } + + return null; + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerMetric.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerMetric.java new file mode 100644 index 0000000000..2405a0eadf --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompLoggerMetric.java @@ -0,0 +1,207 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ALERT_SEVERITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_CLASS_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ELAPSED_TIME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_END_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_INSTANCE_UUID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_KEY_REQUEST_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD1; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD2; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD3; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD4; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PARTNER_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PROCESS_KEY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_REMOTE_HOST; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_DESC; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_FQDN; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_IP_ADDRESS; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_INSTANCE_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_STATUS_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_ENTITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_VIRTUAL_ENTITY; + +import org.openecomp.sdc.common.ecomplog.Enums.LogMarkers; +import org.openecomp.sdc.common.ecomplog.Enums.Severity; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.slf4j.MarkerFactory; + + +public class EcompLoggerMetric extends EcompLoggerBase{ + private static EcompLoggerMetric instanceLoggerMetric = (EcompLoggerMetric) EcompLoggerFactory.getLogger(EcompLoggerMetric.class); + + EcompLoggerMetric(IEcompMdcWrapper ecompMdcWrapper) { + super(ecompMdcWrapper, MarkerFactory.getMarker(LogMarkers.METRIC_MARKER.text())); + } + + public static EcompLoggerMetric getInstance() { + return instanceLoggerMetric; + } + + @Override + public EcompLoggerMetric startTimer() { + return (EcompLoggerMetric) super.startTimer(); + } + + @Override + public EcompLoggerMetric setKeyRequestId(String keyRequestId) { + return (EcompLoggerMetric) super.setKeyRequestId(keyRequestId); + } + + public EcompLoggerMetric stopTimer() { + ecompMdcWrapper.stopTimer(); + return this; + } + + // automatic parameter this is optional + public EcompLoggerMetric setAutoServerFQDN(String serverFQDN) { + ecompMdcWrapper.setAutoServerFQDN(serverFQDN); + return this; + } + + // automatic parameter this is optional + public EcompLoggerMetric setAutoServerIPAddress(String serverIPAddress) { + ecompMdcWrapper.setAutoServerIPAddress(serverIPAddress); + return this; + } + + public EcompLoggerMetric setInstanceUUID(String instanceUUID) { + ecompMdcWrapper.setInstanceUUID(instanceUUID); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptProcessKey(String processKey) { + ecompMdcWrapper.setProcessKey(processKey); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptAlertSeverity(Severity alertSeverity) { + ecompMdcWrapper.setAlertSeverity(alertSeverity); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptCustomField1(String customField1) { + ecompMdcWrapper.setOptCustomField1(customField1); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptCustomField2(String customField2) { + ecompMdcWrapper.setOptCustomField2(customField2); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptCustomField3(String customField3) { + ecompMdcWrapper.setOptCustomField3(customField3); + return this; + } + + // ecomplog optional parameter + public EcompLoggerMetric setOptCustomField4(String customField4) { + ecompMdcWrapper.setOptCustomField4(customField4); + return this; + } + + public EcompLoggerMetric setRemoteHost(String remoteHost) { + ecompMdcWrapper.setRemoteHost(remoteHost); + return this; + } + + public EcompLoggerMetric setServiceName(String serviceName) { + ecompMdcWrapper.setServiceName(serviceName); + return this; + } + + public EcompLoggerMetric setStatusCode(String statusCode) { + ecompMdcWrapper.setStatusCode(statusCode); + return this; + } + + public EcompLoggerMetric setPartnerName(String partnerName) { + ecompMdcWrapper.setPartnerName(partnerName); + return this; + } + + public EcompLoggerMetric setResponseCode(int responseCode) { + ecompMdcWrapper.setResponseCode(responseCode); + return this; + } + + public EcompLoggerMetric setResponseDesc(String responseDesc) { + ecompMdcWrapper.setResponseDesc(responseDesc); + return this; + } + + public EcompLoggerMetric setOptServiceInstanceId(String serviceInstanceId) { + ecompMdcWrapper.setServiceInstanceId(serviceInstanceId); + return this; + } + + public EcompLoggerMetric setOptClassName(String className) { + ecompMdcWrapper.setClassName(className); + return this; + } + + public EcompLoggerMetric setTargetEntity(String targetEntity) { + ecompMdcWrapper.setTargetEntity(targetEntity); + return this; + } + + public EcompLoggerMetric setTargetServiceName(String targetServiceName) { + ecompMdcWrapper.setTargetServiceName(targetServiceName); + return this; + } + + public EcompLoggerMetric setTargetVirtualEntity(String targetVirtualEntity) { + ecompMdcWrapper.setTargetVirtualEntity(targetVirtualEntity); + return this; + } + + @Override + public EcompLoggerMetric clear () { + return (EcompLoggerMetric) super.clear(); + } + + + @Override + public void initializeMandatoryFields() { + + ecompMdcWrapper.setMandatoryField(MDC_BEGIN_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_END_TIMESTAMP); + ecompMdcWrapper.setMandatoryField(MDC_KEY_REQUEST_ID); + ecompMdcWrapper.setMandatoryField(MDC_SERVICE_NAME); + ecompMdcWrapper.setMandatoryField(MDC_PARTNER_NAME); + ecompMdcWrapper.setMandatoryField(MDC_STATUS_CODE); + ecompMdcWrapper.setMandatoryField(MDC_RESPONSE_CODE); + ecompMdcWrapper.setMandatoryField(MDC_SERVICE_INSTANCE_ID); + ecompMdcWrapper.setMandatoryField(MDC_RESPONSE_DESC); + ecompMdcWrapper.setMandatoryField(MDC_ELAPSED_TIME); + ecompMdcWrapper.setMandatoryField(MDC_TARGET_ENTITY); + ecompMdcWrapper.setMandatoryField(MDC_TARGET_SERVICE_NAME); + ecompMdcWrapper.setMandatoryField(MDC_TARGET_VIRTUAL_ENTITY); + + //Theoretically Optional, but practically Mandatory + ecompMdcWrapper.setMandatoryField(MDC_SERVER_IP_ADDRESS); + ecompMdcWrapper.setMandatoryField(MDC_SERVER_FQDN); + + ecompMdcWrapper.setOptionalField(MDC_INSTANCE_UUID); + ecompMdcWrapper.setOptionalField(MDC_ALERT_SEVERITY); + ecompMdcWrapper.setOptionalField(MDC_REMOTE_HOST); + ecompMdcWrapper.setOptionalField(MDC_CLASS_NAME); + ecompMdcWrapper.setOptionalField(MDC_PROCESS_KEY); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD1); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD2); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD3); + ecompMdcWrapper.setOptionalField(MDC_OPT_FIELD4); + + + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompMDCWrapper.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompMDCWrapper.java new file mode 100644 index 0000000000..1d833ec6f9 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/EcompMDCWrapper.java @@ -0,0 +1,290 @@ +package org.openecomp.sdc.common.ecomplog; + +import static java.lang.Integer.valueOf; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ALERT_SEVERITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_CLASS_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ERROR_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ERROR_DESC; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_INSTANCE_UUID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_KEY_REQUEST_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD1; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD2; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD3; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_OPT_FIELD4; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PARTNER_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_PROCESS_KEY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_REMOTE_HOST; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_RESPONSE_DESC; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_FQDN; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVER_IP_ADDRESS; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_INSTANCE_ID; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_STATUS_CODE; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_ENTITY; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_SERVICE_NAME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_TARGET_VIRTUAL_ENTITY; + +import java.net.InetAddress; +import java.util.ArrayList; + +import org.openecomp.sdc.common.ecomplog.Enums.Severity; +import org.openecomp.sdc.common.ecomplog.api.IEcompMdcWrapper; +import org.openecomp.sdc.common.ecomplog.api.IStopWatch; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +public class EcompMDCWrapper implements IEcompMdcWrapper { + + private static EcompMDCWrapper instanceMdcWrapper = new EcompMDCWrapper(new Stopwatch()); + + public static EcompMDCWrapper getInstance() { + return instanceMdcWrapper; + } + + private IStopWatch stopWatch; + protected static Logger log = LoggerFactory.getLogger(EcompMDCWrapper.class.getName()); + protected ArrayList<String> mandatoryFields = new ArrayList<>(); + protected ArrayList<String> optionalFields = new ArrayList<>(); + protected static String hostAddress; + protected static String fqdn; + + // in package classes can instantiate this class + // to use directly from outside the package usr the getInstance() Method + EcompMDCWrapper(IStopWatch stopwatch) { + this.stopWatch = stopwatch; + } + + static { + try { + hostAddress = InetAddress.getLocalHost().getHostAddress(); + fqdn = InetAddress.getByName(hostAddress).getCanonicalHostName(); + } catch (Exception ex) { + log.error("failed to get machine parameters", ex); + } + } + + @Override + public EcompMDCWrapper startTimer() { + stopWatch.start(); + return this; + } + + @Override + public EcompMDCWrapper stopTimer() { + try { + stopWatch.stop(); + } catch (Exception ex) { + log.error("StopWatch failed; probably start was not called before Stopwatch", ex); + } + return this; + } + + @Override + public EcompMDCWrapper setClassName(String className) { + MDC.put(MDC_CLASS_NAME, className); + return this; + } + + // automatic parameter this is optional + @Override + public EcompMDCWrapper setAutoServerFQDN(String serverFQDN) { + MDC.put(MDC_SERVER_FQDN, serverFQDN); + return this; + } + + // automatic parameter this is optional + @Override + public EcompMDCWrapper setAutoServerIPAddress(String serverIPAddress) { + MDC.put(MDC_SERVER_IP_ADDRESS, serverIPAddress); + return this; + } + + @Override + public EcompMDCWrapper setInstanceUUID(String instanceUUID) { + MDC.put(MDC_INSTANCE_UUID, instanceUUID); + return this; + } + + @Override + public EcompMDCWrapper setProcessKey(String processKey) { + MDC.put(MDC_PROCESS_KEY, processKey); + return this; + } + + @Override + public EcompMDCWrapper setAlertSeverity(Severity alertSeverity) { + MDC.put(MDC_ALERT_SEVERITY, String.valueOf(alertSeverity.getSeverityType())); + return this; + } + + @Override + public EcompMDCWrapper setOptCustomField1(String customField1) { + MDC.put(MDC_OPT_FIELD1, customField1); + return this; + } + + @Override + public EcompMDCWrapper setOptCustomField2(String customField2) { + MDC.put(MDC_OPT_FIELD2, customField2); + return this; + } + + @Override + public EcompMDCWrapper setOptCustomField3(String customField3) { + MDC.put(MDC_OPT_FIELD3, customField3); + return this; + } + + @Override + public EcompMDCWrapper setOptCustomField4(String customField4) { + MDC.put(MDC_OPT_FIELD4, customField4); + return this; + } + + @Override + public EcompMDCWrapper setKeyRequestId(String keyRequestId) { + MDC.put(MDC_KEY_REQUEST_ID, keyRequestId); // eg. servletRequest.getSession().getId() + return this; + } + + @Override + public EcompMDCWrapper setRemoteHost(String remoteHost) { + MDC.put(MDC_REMOTE_HOST, remoteHost); + return this; + } + + @Override + public EcompMDCWrapper setServiceName(String serviceName) { + MDC.put(MDC_SERVICE_NAME, serviceName); + return this; + } + + @Override + public EcompMDCWrapper setStatusCode(String statusCode) { + MDC.put(MDC_STATUS_CODE, statusCode); + return this; + } + + @Override + public EcompMDCWrapper setPartnerName(String partnerName) { + MDC.put(MDC_PARTNER_NAME, partnerName); + return this; + } + + @Override + public EcompMDCWrapper setResponseCode(int responseCode) { + MDC.put(MDC_RESPONSE_CODE, Integer.toString(responseCode)); + return this; + } + + @Override + public EcompMDCWrapper setResponseDesc(String responseDesc) { + MDC.put(MDC_RESPONSE_DESC, responseDesc); + return this; + } + + @Override + public EcompMDCWrapper setServiceInstanceId(String serviceInstanceId) { + MDC.put(MDC_SERVICE_INSTANCE_ID, serviceInstanceId); + return this; + } + + @Override + public EcompMDCWrapper setTargetEntity(String targetEntity) { + MDC.put(MDC_TARGET_ENTITY, targetEntity); + return this; + } + + @Override + public EcompMDCWrapper setTargetServiceName(String targetServiceName) { + MDC.put(MDC_TARGET_SERVICE_NAME, targetServiceName); + return this; + } + + @Override + public EcompMDCWrapper setTargetVirtualEntity(String targetVirtualEntity) { + MDC.put(MDC_TARGET_VIRTUAL_ENTITY, targetVirtualEntity); + return this; + } + + @Override + public EcompMDCWrapper setErrorCode(int errorCode) { + MDC.put(MDC_ERROR_CODE, valueOf(errorCode).toString()); + return this; + } + + @Override + public EcompMDCWrapper setErrorDescription(String errorDescription) { + MDC.put(MDC_ERROR_DESC, errorDescription); + return this; + } + + @Override + public void validateMandatoryFields() { + // this method only checks if the mandatory fields have been initialized + String filedNameThatHasNotBeenInitialized = checkMandatoryFieldsExistInMDC(); + + if (MDC.getCopyOfContextMap() == null || MDC.getCopyOfContextMap().isEmpty()) { + writeLogMDCEmptyError(); + return; + } + + if (!"".equalsIgnoreCase(filedNameThatHasNotBeenInitialized)) { + writeLogMissingFieldsError(filedNameThatHasNotBeenInitialized); + } + } + + protected void writeLogMissingFieldsError(String FiledNameThatHasNotBeenInitialized) { + log.error("mandatory parameters for EELF logging, missing fields: %s", FiledNameThatHasNotBeenInitialized); + } + + protected void writeLogMDCEmptyError() { + log.error("write to log when MDC is empty error"); + } + + @Override + public EcompMDCWrapper clear() { + mandatoryFields.forEach(MDC::remove); + optionalFields.forEach(MDC::remove); + return this; + } + + protected String checkMandatoryFieldsExistInMDC() { + // this method returns a String of uninitialised fields + StringBuilder missingFields = new StringBuilder(); + mandatoryFields.forEach(field -> { + if (isMDCParamEmpty(field)) { + missingFields.append(field).append(" "); + } + }); + return missingFields.toString(); + } + + @Override + public void setMandatoryField(String parameterName) { + mandatoryFields.add(parameterName); + } + + @Override + public void setOptionalField(String parameterName) { + optionalFields.add(parameterName); + } + + @Override + public boolean isMDCParamEmpty(String mdcKeyName) { + String val = MDC.get(mdcKeyName); + return (val == null || val.trim().length() == 0); + } + + @Override + public String getFqdn() { + return fqdn; + } + + @Override + public String getHostAddress() { + return hostAddress; + } +}
\ No newline at end of file diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/EcompLoggerErrorCode.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/EcompLoggerErrorCode.java new file mode 100644 index 0000000000..c6862656bb --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/EcompLoggerErrorCode.java @@ -0,0 +1,24 @@ +package org.openecomp.sdc.common.ecomplog.Enums; + +/** + * 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); + + int errorCode; + + EcompLoggerErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public int getErrorCode() { + return errorCode; + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogLevel.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogLevel.java new file mode 100644 index 0000000000..2fc7d7f26f --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogLevel.java @@ -0,0 +1,13 @@ +package org.openecomp.sdc.common.ecomplog.Enums; + +/** + * Created by dd4296 on 12/14/2017. + */ +public enum LogLevel { + INFO, + WARN, + DEBUG, + ERROR, + FATAL +} + diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogMarkers.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogMarkers.java new file mode 100644 index 0000000000..b26e8c105d --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/LogMarkers.java @@ -0,0 +1,23 @@ +package org.openecomp.sdc.common.ecomplog.Enums; + +/** + * Created by mm288v on 12/27/2017. + * This enum reflects the Marker text in logback.xml file per each ecomp marker + */ +public enum LogMarkers { + DEBUG_MARKER("DEBUG_MARKER"), + ERROR_MARKER("ERROR_MARKER"), + AUDIT_MARKER("AUDIT_MARKER"), + METRIC_MARKER("METRICS"); + + private String text; + + LogMarkers (String text){ + this.text = text; + } + + public String text(){ + return text; + } + +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/Severity.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/Severity.java new file mode 100644 index 0000000000..f842927af2 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/Severity.java @@ -0,0 +1,23 @@ +package org.openecomp.sdc.common.ecomplog.Enums; + +/** + * Created by dd4296 on 12/14/2017. + */ +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-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/StatusCode.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/StatusCode.java new file mode 100644 index 0000000000..2fdd96f11b --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Enums/StatusCode.java @@ -0,0 +1,14 @@ +package org.openecomp.sdc.common.ecomplog.Enums; + +public enum StatusCode { + ERROR("ERROR"), + COMPLETE("COMPLETE"); + + String statusCode; + + StatusCode(String statusCode){this.statusCode = statusCode;} + + public String getStatusCodeEnum(){ + return statusCode; + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Stopwatch.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Stopwatch.java new file mode 100644 index 0000000000..76262e7815 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/Stopwatch.java @@ -0,0 +1,61 @@ +package org.openecomp.sdc.common.ecomplog; + +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_ELAPSED_TIME; +import static org.openecomp.sdc.common.ecomplog.api.IEcompLogConfiguration.MDC_END_TIMESTAMP; + +import java.time.Clock; +import java.time.Duration; +import java.time.LocalDateTime; + +import org.openecomp.sdc.common.ecomplog.api.IStopWatch; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +/** + * Created by dd4296 on 12/13/2017. + * this is local implementation of the stopwatch class from EELF standard with the same interface + * can be replaced if needed with EELF lib + */ +public class Stopwatch implements IStopWatch { + + private static Logger log = LoggerFactory.getLogger(Stopwatch.class.getName()); + + public Stopwatch() { + } + + public void start() { + if (MDC.get(MDC_BEGIN_TIMESTAMP) == null || MDC.get(MDC_BEGIN_TIMESTAMP).trim().length() == 0) + MDC.put(MDC_BEGIN_TIMESTAMP, generatedTimeNow()); + } + + public void stop() { + if (MDC.get(MDC_BEGIN_TIMESTAMP) == null) { + log.error("call to stop without calling start first, this is not compliant with EELF format"); + } + MDC.put(MDC_END_TIMESTAMP, generatedTimeNow()); + setElapsedTime(); + } + + private void setElapsedTime() { + + try { + + final LocalDateTime startTime = LocalDateTime.parse(MDC.get(MDC_BEGIN_TIMESTAMP)); + final LocalDateTime endTime = LocalDateTime.parse(MDC.get(MDC_END_TIMESTAMP)); + + final Duration timeDifference = Duration.between(startTime, endTime); + + MDC.put(MDC_ELAPSED_TIME, String.valueOf(timeDifference.toMillis())); + + } catch(Exception ex) { + log.error("failed to calculate elapsed time",ex); + } + } + + private String generatedTimeNow() { + return String.valueOf(LocalDateTime.now(Clock.systemUTC())); + } + +}
\ No newline at end of file diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogConfiguration.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogConfiguration.java new file mode 100644 index 0000000000..6521ea78e1 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogConfiguration.java @@ -0,0 +1,42 @@ +package org.openecomp.sdc.common.ecomplog.api; + +public interface IEcompLogConfiguration { + String PROPERTY_LOGGING_FILE_NAME = "com.att.ecomplog.logging.file"; + String PROPERTY_LOGGING_FILE_PATH = "com.att.ecomplog.logging.path"; + String GENERAL_LOGGER_NAME = "com.att.ecomplog"; + String METRICS_LOGGER_NAME = "com.att.ecomplog.metrics"; + String PERF_LOGGER_NAME = "com.att.ecomplog.perf"; + String POLICY_LOGGER_NAME = "com.att.ecomplog.policy"; + String SECURITY_LOGGER_NAME = "com.att.ecomplog.security"; + String SERVER_LOGGER_NAME = "com.att.ecomplog.server"; + String AUDIT_LOGGER_NAME = "com.att.ecomplog.audit"; + String ERROR_LOGGER_NAME = "com.att.ecomplog.error"; + String DEBUG_LOGGER_NAME = "com.att.ecomplog.debug"; + String MDC_KEY_REQUEST_ID = "RequestId"; + String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceId"; + String MDC_SERVICE_NAME = "ServiceName"; + String MDC_INSTANCE_UUID = "InstanceUUID"; + String MDC_SERVER_IP_ADDRESS = "ServerIPAddress"; + String MDC_SERVER_FQDN = "ServerFQDN"; + String MDC_REMOTE_HOST = "RemoteHost"; + String MDC_ALERT_SEVERITY = "AlertSeverity"; + String MDC_BEGIN_TIMESTAMP = "BeginTimestamp"; + String MDC_END_TIMESTAMP = "EndTimestamp"; + String MDC_PARTNER_NAME = "PartnerName"; + String MDC_STATUS_CODE = "StatusCode"; + String MDC_RESPONSE_CODE = "ResponseCode"; + String MDC_RESPONSE_DESC = "ResponseDescription"; + String MDC_ELAPSED_TIME = "ElapsedTime"; + String MDC_PROCESS_KEY = "ProcessKey"; + String MDC_TARGET_ENTITY = "TargetEntity"; + String MDC_TARGET_SERVICE_NAME = "TargetServiceName"; + String MDC_TARGET_VIRTUAL_ENTITY = "TargetVirtualEntity"; + String MDC_ERROR_CATEGORY = "ErrorCategory"; + String MDC_ERROR_CODE = "ErrorCode"; + String MDC_ERROR_DESC = "ErrorDescription"; + String MDC_CLASS_NAME = "ClassName"; + String MDC_OPT_FIELD1 = "CustomField1"; + String MDC_OPT_FIELD2 = "CustomField2"; + String MDC_OPT_FIELD3 = "CustomField3"; + String MDC_OPT_FIELD4 = "CustomField4"; +}
\ No newline at end of file diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogger.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogger.java new file mode 100644 index 0000000000..569343eaf6 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompLogger.java @@ -0,0 +1,14 @@ +package org.openecomp.sdc.common.ecomplog.api; + +import org.openecomp.sdc.common.ecomplog.Enums.LogLevel; + +/** + * Created by dd4296 on 12/24/2017. + */ +public interface IEcompLogger { + void log(LogLevel errorLevel, String message); + void initializeMandatoryFields(); + IEcompLogger clear(); + IEcompLogger startTimer(); + IEcompLogger setKeyRequestId(String keyRequestId); +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompMdcWrapper.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompMdcWrapper.java new file mode 100644 index 0000000000..37d77fd6c5 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IEcompMdcWrapper.java @@ -0,0 +1,75 @@ +package org.openecomp.sdc.common.ecomplog.api; + +import org.openecomp.sdc.common.ecomplog.EcompMDCWrapper; +import org.openecomp.sdc.common.ecomplog.Enums.Severity; + +/** + * Created by dd4296 on 12/25/2017. + */ +public interface IEcompMdcWrapper { + EcompMDCWrapper startTimer(); + + EcompMDCWrapper stopTimer(); + + EcompMDCWrapper setClassName(String className); + + // automatic parameter this is optional + EcompMDCWrapper setAutoServerFQDN(String serverFQDN); + + // automatic parameter this is optional + EcompMDCWrapper setAutoServerIPAddress(String serverIPAddress); + + EcompMDCWrapper setInstanceUUID(String instanceUUID); + + EcompMDCWrapper setProcessKey(String processKey); + + EcompMDCWrapper setAlertSeverity(Severity alertSeverity); + + EcompMDCWrapper setOptCustomField1(String customField1); + + EcompMDCWrapper setOptCustomField2(String customField2); + + EcompMDCWrapper setOptCustomField3(String customField3); + + EcompMDCWrapper setOptCustomField4(String customField4); + + EcompMDCWrapper setKeyRequestId(String keyRequestId); + + EcompMDCWrapper setRemoteHost(String remoteHost); + + EcompMDCWrapper setServiceName(String serviceName); + + EcompMDCWrapper setStatusCode(String statusCode); + + EcompMDCWrapper setPartnerName(String partnerName); + + EcompMDCWrapper setResponseCode(int responseCode); + + EcompMDCWrapper setResponseDesc(String responseDesc); + + EcompMDCWrapper setServiceInstanceId(String serviceInstanceId); + + EcompMDCWrapper setTargetEntity(String targetEntity); + + EcompMDCWrapper setTargetServiceName(String targetServiceName); + + EcompMDCWrapper setTargetVirtualEntity(String targetVirtualEntity); + + EcompMDCWrapper setErrorCode(int errorCode); + + EcompMDCWrapper setErrorDescription(String errorDescription); + + EcompMDCWrapper clear(); + + void validateMandatoryFields(); + + void setMandatoryField(String mdcKeyRequestId); + + void setOptionalField(String mdcKeyRequestId); + + boolean isMDCParamEmpty(String mdcKeyName); + + String getFqdn(); + + String getHostAddress(); +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IStopWatch.java b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IStopWatch.java new file mode 100644 index 0000000000..4f1649cef1 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/ecomplog/api/IStopWatch.java @@ -0,0 +1,11 @@ +package org.openecomp.sdc.common.ecomplog.api; + +/** + * Created by dd4296 on 12/14/2017. + * + * stop watch interface compliant with ecomplog stop watch class + */ +public interface IStopWatch { + void start(); + void stop(); +} |