import java.text.SimpleDateFormat;
import java.util.Date;
+import org.apache.commons.lang3.StringUtils;
import org.onap.so.entity.MsoRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static final String RESPONSECODE = "ResponseCode";
public static final String RESPONSEDESC = "ResponseDesc";
public static final String FQDN = "ServerFQDN";
+ public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
+ public static final String CLIENT_IPADDRESS = "EntryTimestamp";
- public static final String SERVICE_INSTANCE_ID = "ServiceInstanceId";
+ //HTTP Headers
+ public static final String HEADER_FROM_APP_ID = "X-FromAppId";
+ public static final String ONAP_PARTNER_NAME = "X-ONAP-PartnerName";
+ public static final String HEADER_REQUEST_ID = "X-RequestId";
+ public static final String TRANSACTION_ID = "X-TransactionID";
+ public static final String ECOMP_REQUEST_ID = "X-ECOMP-RequestID";
+ public static final String ONAP_REQUEST_ID = "X-ONAP-RequestID";
+ public static final String CLIENT_ID = "X-ClientID";
+ public static final String INVOCATION_ID_HEADER = "X-InvocationID";
+ public static final String REQUESTOR_ID = "X-RequestorID";
+
+ //Default values for not found
+ public static final String UNKNOWN_PARTNER = "UnknownPartner";
+ public static final String SERVICE_INSTANCE_ID = "ServiceInstanceId";
public static final String SERVICE_NAME_IS_METHOD_NAME = "ServiceNameIsMethodName";
- public static final String SERVER_IP = "ServerIPAddress";
-
+ public static final String SERVER_IP = "ServerIPAddress";
public static final String REMOTE_HOST = "RemoteHost";
public static final String ALERT_SEVERITY = "AlertSeverity";
public static final String CAT_LOG_LEVEL = "CategoryLogLevel";
public static final String AUDI_CAT_LOG_LEVEL = "AuditCategoryLogLevel";
- //For getting an identity of calling application
- public static final String HEADER_FROM_APP_ID = "X-FromAppId";
- public static final String FROM_APP_ID = "FromAppId";
- public static final String HEADER_REQUEST_ID = "X-RequestId";
- public static final String TRANSACTION_ID = "X-TransactionID";
- public static final String ECOMP_REQUEST_ID = "X-ECOMP-RequestID";
- public static final String ONAP_REQUEST_ID = "X-ONAP-RequestID";
-
- public static final String CLIENT_ID = "X-ClientID";
- public static final String INVOCATION_ID_HEADER = "X-InvocationID";
-
+
+
+ public static final String PARTNER_NAME = "PartnerName";
+
// Audit/Metric log specific
public static final String BEGINTIME = "BeginTimestamp";
public static final String STARTTIME = "StartTimeMilis";
this.value = value;
}
}
-
- public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
- public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
+
private Logger logger;
private Logger metricsLogger;
private static String instanceUUID, serverIP, serverName;
private MessageEnum exceptionArg, defaultException, defaultWarning, defaultAudit, defaultMetrics;
- // For internal logging of the initialization of MSO logs
- private static final Logger initLOGGER = LoggerFactory.getLogger(MsoLogger.class.getName());
-
private MsoLogger() {
this(MsoLogger.Catalog.GENERAL);
}
private MsoLogger(MsoLogger.Catalog cat, Class<?> clazz) {
this.logger = LoggerFactory.getLogger(clazz);
this.auditLogger = LoggerFactory.getLogger("AUDIT");
- this.metricsLogger = LoggerFactory.getLogger("METRIC");
- MsoLogger.initialization();
+ this.metricsLogger = LoggerFactory.getLogger("METRIC");
setDefaultLogCatalog(cat);
}
-
- private static synchronized void initialization() {
- if (instanceUUID == null || ("").equals(instanceUUID)) {
- instanceUUID = getInstanceUUID();
- }
-
- if (serverIP == null || serverName == null || ("").equals(serverIP) || ("").equals(serverName)) {
- try {
- InetAddress server = InetAddress.getLocalHost();
- serverIP = server.getHostAddress();
- serverName = server.getHostName();
- } catch (UnknownHostException e) {
- initLOGGER.error("Could not get local hostname", e);
- serverIP = "";
- serverName = "";
- }
- }
- }
-
-
public static MsoLogger getMsoLogger(MsoLogger.Catalog cat, Class<?> clazz) {
return new MsoLogger(cat,clazz);
* @param targetVEntity
* Target VNF or VM acted opon by the component, if available
*/
- public void recordMetricEvent() {
- metricsLogger.info("");
- MDC.remove(TIMER);
- MDC.remove(TARGETENTITY);
- MDC.remove(TARGETSERVICENAME);
- }
public void recordMetricEvent(Long startTime, StatusCode statusCode, ResponseCode responseCode, String responseDesc,
String targetEntity, String targetServiceName, String targetVEntity) {
* @param responseDesc
* Human redable description of the application response code
*/
- public void recordAuditEvent(){
- auditLogger.info("");
- }
-
+
public void recordAuditEvent(Long startTime, StatusCode statusCode, ResponseCode responseCode,
String responseDesc) {
- MDC.put(MsoLogger.PARTNERNAME, "UNKNOWN");
+ if (StringUtils.isEmpty(MDC.get(MsoLogger.PARTNERNAME))) {
+ MDC.put(MsoLogger.PARTNERNAME, "UNKNOWN");
+ }
prepareAuditMsg(startTime, statusCode, responseCode.getValue(), responseDesc);
auditLogger.info("");
MDC.remove(TIMER);
MDC.remove(TARGETSERVICENAME);
}
-
- public void logStackTrace(Exception ex){
- StringWriter errors = new StringWriter();
- ex.printStackTrace(new PrintWriter(errors));
- logger.error(errors.toString());
- }
-
- public boolean isDebugEnabled() {
- return logger.isDebugEnabled();
- }
private void prepareMsg(String loggingLevel) {
prepareMsg(loggingLevel, null, null);
MDC.put(ERRORDESC, errorDesc);
MDC.put(TARGETENTITY, targetEntity);
MDC.put(TARGETSERVICENAME, targetServiceName);
- MDC.put(SERVICE_NAME, getFinalServiceName(getServiceName()));
}
private void prepareMetricMsg(long startTime, StatusCode statusCode, int responseCode, String responseDesc,
return classArr[0].getMethodName();
}
- // Based on the discussion with Adrian, instanceUUID is used to identifiy
- // the mso instance,
- // it is generated during mso instance initialization period
- // The same mso instnace will use the same instanceUUID value, even after
- // restart
- private static String getInstanceUUID() {
- return System.getProperty("mso-instance-id");
- }
-
/**
* Set the requestId and serviceInstanceId
- *
+ *
* @param reqId
* The requestId
* @param svcId
}
}
- /**
- * Set the remoteIp and the basic HTTP Authentication user
- *
- * @param remoteIpp
- * The remote ip address
- * @param userp
- * The basic http authencitation user
- */
- public static void setLoggerParameters(String remoteIpp, String userp) {
- if (null != remoteIpp) {
- MDC.put(REMOTE_HOST, remoteIpp);
- }
- if (null != userp) {
- MDC.put(USER, userp);
- }
- }
-
- /**
- * Set the serviceName
- *
- * @param serviceNamep
- * The service name
- */
- public static void setServiceName(String serviceNamep) {
- if (null != serviceNamep) {
- MDC.put(SERVICE_NAME, serviceNamep);
- MDC.remove(SERVICE_NAME_IS_METHOD_NAME);
- }
- }
-
/**
* Get the serviceName
*
return MDC.get(SERVICE_NAME);
}
- /**
- * Reset the serviceName
- */
- public static void resetServiceName() {
- MDC.remove(SERVICE_NAME);
- }
-
- /**
- * Set the requestId and serviceInstanceId based on the mso request
- *
- * @param msoRequest
- * The mso request
- */
- public static void setLogContext(MsoRequest msoRequest) {
- if (msoRequest != null) {
- MDC.put(REQUEST_ID, msoRequest.getRequestId());
- MDC.put(SERVICE_INSTANCE_ID, msoRequest.getServiceInstanceId());
- } else {
- MDC.put(REQUEST_ID, DUMMY_VALUE);
- MDC.put(SERVICE_INSTANCE_ID, DUMMY_VALUE);
- }
- }
-
private String normalize(String input) {
if (input == null) {
return null;
defaultMetrics = MessageEnum.GENERAL_METRICS;
}
}
-
- public void warnSimple(String message, Exception e) {
- logger.warn(message,e);
-
- }
-
-
-
-
-
}