summaryrefslogtreecommitdiffstats
path: root/reference/logging-slf4j
diff options
context:
space:
mode:
authorMichael O'Brien <frank.obrien@amdocs.com>2018-06-25 13:59:31 -0400
committerMichael O'Brien <frank.obrien@amdocs.com>2018-07-10 23:45:29 -0400
commit9eee6ac9daa5b82946b4f7c7eaa817ae3e1f4cab (patch)
treec92bf95da779589a1162044b4f77a51876fccb7b /reference/logging-slf4j
parent9aaa8f39949d7dc3d66888797951a20a7bced145 (diff)
logging library use and k8s
Change-Id: I264f6dd5270543a216612c50fd5806458e0e806a Issue-ID: LOG-135 Signed-off-by: Michael O'Brien <frank.obrien@amdocs.com>
Diffstat (limited to 'reference/logging-slf4j')
-rw-r--r--reference/logging-slf4j/pom.xml4
-rw-r--r--reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java3
-rw-r--r--reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java41
3 files changed, 44 insertions, 4 deletions
diff --git a/reference/logging-slf4j/pom.xml b/reference/logging-slf4j/pom.xml
index 9cc9d4b..138f7de 100644
--- a/reference/logging-slf4j/pom.xml
+++ b/reference/logging-slf4j/pom.xml
@@ -3,14 +3,12 @@
<parent>
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-reference</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>logging-slf4j</artifactId>
<name>logging-slf4j</name>
<packaging>jar</packaging>
- <version>1.2.0-SNAPSHOT</version>
-
<dependencies>
<!-- Exported dependencies. -->
<dependency>
diff --git a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java
index d26cd13..aafc74d 100644
--- a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java
+++ b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java
@@ -333,7 +333,8 @@ public class ONAPLogAdapter {
// Default the service name to the requestURI, in the event that
// no value has been provided.
- if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null) {
+ if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null ||
+ MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) {
MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI());
}
diff --git a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
index b14df9f..1d11bd3 100644
--- a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
+++ b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
@@ -166,6 +166,47 @@ public class ONAPLogAdapterTest {
MDC.clear();
}
}
+
+ /**
+ * Test ENTERING with an EMPTY_STRING serviceName.
+ */
+ @Test
+ public void testEnteringWithEMPTY_STRING_serviceName() {
+
+ final Logger logger = LoggerFactory.getLogger(this.getClass());
+ final ONAPLogAdapter adapter = new ONAPLogAdapter(logger);
+ final MockHttpServletRequest http = new MockHttpServletRequest();
+ http.setRequestURI("uri123");
+ http.setServerName("local123");
+ http.setRemoteAddr("remote123");
+ http.addHeader("X-ONAP-RequestID", "request123");
+ http.addHeader("X-ONAP-InvocationID", "invocation123");
+ http.addHeader("X-ONAP-PartnerName", "partner123");
+
+ try {
+ // an empty string should kick in setting the actual service name (treated same as null)
+ adapter.getServiceDescriptor().setServiceName("");
+ adapter.entering(http);
+ final Map<String, String> mdcs = MDC.getCopyOfContextMap();
+ assertThat(mdcs.get("RequestID"), is("request123"));
+ assertThat(mdcs.get("InvocationID"), is("invocation123"));
+ assertThat(mdcs.get("PartnerName"), is("partner123"));
+ assertThat(mdcs.get("ServiceName"), is("uri123"));
+ assertThat(mdcs.get("ServerFQDN"), is("local123"));
+ assertThat(mdcs.get("ClientIPAddress"), is("remote123"));
+
+ // Timestamp format and value:
+
+ final String invokeTimestampString = mdcs.get("InvokeTimestamp");
+ assertThat(invokeTimestampString, notNullValue());
+ assertThat(invokeTimestampString, endsWith("Z"));
+ final long invokeTimestamp = DatatypeConverter.parseDateTime(invokeTimestampString).getTimeInMillis();
+ assertThat(Math.abs(System.currentTimeMillis() - invokeTimestamp), lessThan(5000L));
+ }
+ finally {
+ MDC.clear();
+ }
+ }
@Test
public void testSetServiceDescriptor() {