summaryrefslogtreecommitdiffstats
path: root/common-logging/src
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src')
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java113
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java10
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java104
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java3
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java32
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java3
6 files changed, 193 insertions, 72 deletions
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
index 71e75a11..e6e2b1ca 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
@@ -75,6 +75,10 @@ public class ECOMPLoggingContext {
private static final String THREAD_ID = "threadId";
private static final String SERVER_NAME = "serverName";
private static final String SERVICE_NAME = "serviceName";
+ private static final String PARTNER_NAME = "partnerName";
+ private static final String STATUS_CODE = "statusCode";
+ private static final String TARGET_ENTITY = "targetEntity";
+ private static final String TARGET_SERVICE_NAME = "targetServiceName";
private static final String INSTANCE_UUID = "instanceUuid";
private static final String SEVERITY = "severity";
private static final String SERVER_IP_ADDRESS = "serverIpAddress";
@@ -123,6 +127,11 @@ public class ECOMPLoggingContext {
MDC.clear();
baseContext.context.transferTo(context);
transactionStartTime = baseContext.transactionStartTime;
+ setServiceName("POLICY");
+ setPartnerName("USER");
+ setStatusCode("COMPLETE");
+ setTargetEntity("POLICY");
+ setTargetServiceName("PE Process");
}
/**
@@ -253,6 +262,70 @@ public class ECOMPLoggingContext {
}
/**
+ * Set the value for the data item with key "partnerName"
+ *
+ * @param id
+ */
+ public void setPartnerName(String name) {
+ context.put(PARTNER_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "partnerName"
+ * @return current value, or empty string if not set
+ */
+ public String getPartnerName() {
+ return context.get(PARTNER_NAME, "");
+ }
+
+ /**
+ * Set the value for the data item with key "statusCode"
+ *
+ * @param id
+ */
+ public void setStatusCode(String name) {
+ context.put(STATUS_CODE, name);
+ }
+ /**
+ * Get the value for the data item with key "statusCode"
+ * @return current value, or empty string if not set
+ */
+ public String getStatusCode() {
+ return context.get(STATUS_CODE, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetEntity"
+ *
+ * @param id
+ */
+ public void setTargetEntity(String name) {
+ context.put(TARGET_ENTITY, name);
+ }
+ /**
+ * Get the value for the data item with key "targetEntity"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetEntity() {
+ return context.get(TARGET_ENTITY, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetServiceName"
+ *
+ * @param id
+ */
+ public void setTargetServiceName(String name) {
+ context.put(TARGET_SERVICE_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "targetServiceName"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetServiceName() {
+ return context.get(TARGET_SERVICE_NAME, "");
+ }
+
+ /**
* Set the value for the data item with key "instanceUuid"
*
* @param id
@@ -433,17 +506,17 @@ public class ECOMPLoggingContext {
*/
public void setTransactionElapsedTime(Instant transactionEndTime) {
- long ns = Duration.between(transactionStartTime, transactionEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(TRANSACTION_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(TRANSACTION_ELAPSED_TIME, ns); // + unit);
}
/**
@@ -506,17 +579,17 @@ public class ECOMPLoggingContext {
*/
public void setMetricElapsedTime(Instant metricEndTime) {
- long ns = Duration.between(metricStartTime, metricEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(metricStartTime, metricEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(METRIC_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(METRIC_ELAPSED_TIME, ns); // + unit);
}
/**
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
index a2a0b783..a839ea16 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
@@ -43,6 +43,16 @@ public interface Configuration extends com.att.eelf.configuration.Configuration
*/
public String PARTNER_NAME = "PartnerName";
+ /**
+ * Target Entity
+ */
+ public String TARGET_ENTITY = "TargetEntity";
+
+ /**
+ * Target service name
+ */
+ public String TARGET_SERVICE_NAME = "TargetServiceName";
+
/**
* High level success or failure (COMPLETE or ERROR)
*/
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
index 624ba580..ed03f9a9 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
@@ -125,7 +125,13 @@ public class PolicyLogger {
}
if(component != null && component.equalsIgnoreCase("DROOLS")){
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "drools evaluate rule");
return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
+ } else {
+ // For Xacml
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "PE Process");
}
MDC.put(MDC_REMOTE_HOST, "");
@@ -140,16 +146,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -161,11 +167,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -203,16 +209,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
@@ -222,7 +228,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
return transId;
}
@@ -234,16 +240,16 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -255,11 +261,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -315,7 +321,7 @@ public class PolicyLogger {
}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
return transId;
@@ -634,7 +640,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(String className, Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, className);
auditLogger.info("" + arg0);
}
@@ -644,7 +650,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, "");
auditLogger.info("" + arg0);
}
@@ -748,7 +754,7 @@ public class PolicyLogger {
*/
public static void recordAuditEventStart(String eventId) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
postMDCInfoForEvent(eventId);
if(eventTracker == null){
@@ -955,21 +961,21 @@ public class PolicyLogger {
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
- serviceName, rule, startTime.toString(), endTime.toString(), ns+unit, policyVersion);
+ serviceName, rule, startTime.toString(), endTime.toString(), Long.toString(ns), policyVersion);
//--- remove the record from the concurrentHashMap
if(eventTracker != null){
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
index 6e74b94c..31c17554 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -33,7 +34,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
*
*/
-public class EelfLogger implements Logger {
+public class EelfLogger implements Logger, Serializable {
private String className = "";
private String transId = UUID.randomUUID().toString();
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
index 02f95cf2..23cafb41 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
@@ -20,6 +20,10 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.UUID;
import org.apache.log4j.Logger;
@@ -34,7 +38,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* Logger4J implements all the methods of interface Logger by calling org.apache.log4j.Logger
*
*/
-public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger {
+public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger, Serializable {
private Logger log = null;
private String methodName = "";
@@ -451,4 +455,30 @@ public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.
public void postMDCInfoForEvent(Object o){
log.info(o);
}
+
+ /* ============================================================ */
+
+ /*
+ * Support for 'Serializable' --
+ * the default rules don't work for the 'log' field
+ */
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // write out 'methodName', 'className', 'transId' strings
+ out.writeObject(methodName);
+ out.writeObject(className);
+ out.writeObject(transId);
+ }
+
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ // read in 'methodName', 'className', 'transId' strings
+ methodName = (String)(in.readObject());
+ className = (String)(in.readObject());
+ transId = (String)(in.readObject());
+
+ // look up associated logger
+ log = Logger.getLogger(className);
+ }
}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
index 26f06640..91e16b97 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -31,7 +32,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* SystemOutLogger implements all the methods of interface Logger by calling System.out.println
*
*/
-public class SystemOutLogger implements Logger {
+public class SystemOutLogger implements Logger, Serializable {
private String className = "";
private boolean isDebugEnabled = true;