aboutsummaryrefslogtreecommitdiffstats
path: root/reference/logging-demo
diff options
context:
space:
mode:
Diffstat (limited to 'reference/logging-demo')
-rw-r--r--reference/logging-demo/.classpath2
-rw-r--r--reference/logging-demo/pom.xml21
-rw-r--r--reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java11
-rw-r--r--reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java4
-rw-r--r--reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java55
-rw-r--r--reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java8
-rw-r--r--reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java25
-rw-r--r--reference/logging-demo/src/main/resources/logback.xml32
-rw-r--r--reference/logging-demo/src/main/webapp/WEB-INF/spring.xml5
-rw-r--r--reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java45
10 files changed, 188 insertions, 20 deletions
diff --git a/reference/logging-demo/.classpath b/reference/logging-demo/.classpath
index 159bf9a..9a77030 100644
--- a/reference/logging-demo/.classpath
+++ b/reference/logging-demo/.classpath
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/test/java"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/logging-library">
<attributes>
<attribute name="module" value="true"/>
diff --git a/reference/logging-demo/pom.xml b/reference/logging-demo/pom.xml
index a695970..60fbe98 100644
--- a/reference/logging-demo/pom.xml
+++ b/reference/logging-demo/pom.xml
@@ -3,14 +3,15 @@
<parent>
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-reference</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
</parent>
<artifactId>logging-demo</artifactId>
<packaging>war</packaging>
<name>logging-demo</name>
<properties>
<jackson-2-version>2.5.1</jackson-2-version>
- <spring.version>4.3.6.RELEASE</spring.version>
+ <spring.version>4.3.6.RELEASE</spring.version>
+ <logback.version>1.2.3</logback.version>
</properties>
<build>
<plugins>
@@ -71,12 +72,12 @@
<dependency>
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-library</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-mock-service</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
</dependency>
@@ -252,6 +253,16 @@
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java
index d0355df..d6329e2 100644
--- a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java
+++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationService.java
@@ -20,14 +20,23 @@
*/
package org.onap.demo.logging;
+import javax.servlet.http.HttpServletRequest;
+
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service("daoFacade")
+/**
+ * Run with http://localhost:8080/logging-demo/rest/health/health
+ *
+ */
public class ApplicationService implements ApplicationServiceLocal {
@Override
- public Boolean health() {
+ public Boolean health(HttpServletRequest servletRequest) {
Boolean health = true;
// TODO: check database
+ // Log outside the AOP framework - to simulate existing component logs between the ENTRY/EXIT markers
+ LoggerFactory.getLogger(this.getClass()).info("Running /health");
return health;
}
diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java
index ac585fb..e2cd5b7 100644
--- a/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java
+++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/ApplicationServiceLocal.java
@@ -20,6 +20,8 @@
*/
package org.onap.demo.logging;
+import javax.servlet.http.HttpServletRequest;
+
public interface ApplicationServiceLocal {
- Boolean health();
+ Boolean health(HttpServletRequest request);
}
diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java
new file mode 100644
index 0000000..2901ce1
--- /dev/null
+++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/LoggingAspect.java
@@ -0,0 +1,55 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.logging
+ * ================================================================================
+ * Copyright © 2018 Amdocs
+ * 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.onap.demo.logging;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.onap.logging.ref.slf4j.ONAPLogAdapter;
+import org.slf4j.LoggerFactory;
+
+@Aspect
+public class LoggingAspect {
+
+ @Before("execution(* org.onap.demo.logging.*.*(..))")
+ public void logBefore(JoinPoint joinPoint) {
+ Object[] args = joinPoint.getArgs();
+ Object servletRequest = args[0];
+ ONAPLogAdapter.HttpServletRequestAdapter requestAdapter =
+ new ONAPLogAdapter.HttpServletRequestAdapter((HttpServletRequest)servletRequest);
+ final ONAPLogAdapter adapter = new ONAPLogAdapter(
+ LoggerFactory.getLogger(joinPoint.getTarget().getClass()));
+ try {
+ adapter.entering(requestAdapter);
+ } finally {
+ }
+ }
+
+ @After("execution(* org.onap.demo.logging.*.*(..))")
+ public void logAfter(JoinPoint joinPoint) {
+ final ONAPLogAdapter adapter = new ONAPLogAdapter(
+ LoggerFactory.getLogger(joinPoint.getTarget().getClass()));
+ adapter.exiting();
+ }
+}
diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java
index 33e3874..bcc4efb 100644
--- a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java
+++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestHealthServiceImpl.java
@@ -21,16 +21,21 @@
package org.onap.demo.logging;
import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.springframework.beans.factory.annotation.Qualifier;
@Path("/health")
public class RestHealthServiceImpl extends Application {
+
+ @Context private HttpServletRequest servletRequest;
+
@Inject
@Qualifier("daoFacade")
private ApplicationServiceLocal applicationServiceLocal;
@@ -39,7 +44,8 @@ public class RestHealthServiceImpl extends Application {
@Path("/health")
@Produces(MediaType.TEXT_HTML)
public String getHealth() {
- return applicationServiceLocal.health().toString();
+
+ return applicationServiceLocal.health(servletRequest).toString();
}
}
diff --git a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java
index 9dfe884..fe13f0c 100644
--- a/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java
+++ b/reference/logging-demo/src/main/java/org/onap/demo/logging/RestServiceImpl.java
@@ -31,19 +31,20 @@ import org.springframework.beans.factory.annotation.Qualifier;
@Path("/read")
public class RestServiceImpl extends Application {
- @Inject
- @Qualifier("daoFacade")
+ @Inject
+ @Qualifier("daoFacade")
private ApplicationServiceLocal applicationServiceLocal;
-
- @GET
- @Path("/test")
- @Produces(MediaType.TEXT_HTML)
- public String getTest() {
- return "testing: " + applicationServiceLocal;
- }
- private ApplicationServiceLocal getApplicationService() {
- return applicationServiceLocal;
- }
+ @GET
+ @Path("/test")
+ @Produces(MediaType.TEXT_HTML)
+ public String getTest() {
+ return "testing: " + applicationServiceLocal;
+
+ }
+
+ private ApplicationServiceLocal getApplicationService() {
+ return applicationServiceLocal;
+ }
}
diff --git a/reference/logging-demo/src/main/resources/logback.xml b/reference/logging-demo/src/main/resources/logback.xml
new file mode 100644
index 0000000..71d41e4
--- /dev/null
+++ b/reference/logging-demo/src/main/resources/logback.xml
@@ -0,0 +1,32 @@
+<configuration>
+ <property name="p_tim" value="%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC}"/>
+ <property name="p_lvl" value="%level"/>
+ <property name="p_log" value="%logger"/>
+ <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/>
+ <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_thr" value="%thread"/>
+ <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>output.log</file>
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <logger level="INFO" name="org.onap.logging.ref.slf4j" additivity="false">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </logger>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git a/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml b/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml
index 32d1235..2b4d585 100644
--- a/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml
+++ b/reference/logging-demo/src/main/webapp/WEB-INF/spring.xml
@@ -34,6 +34,11 @@
</context:component-scan>
<!-- Rest controllers -->
<context:component-scan base-package="org.onap.demo.logging" />
+ <!-- enable logging AOP proxies -->
+ <aop:aspectj-autoproxy />
+ <beans>
+ <bean class="org.onap.demo.logging.LoggingAspect" /> <!-- required even though we annotate with @Aspect -->
+ </beans>
</beans>
diff --git a/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java b/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java
new file mode 100644
index 0000000..aab2ba7
--- /dev/null
+++ b/reference/logging-demo/src/test/java/org/onap/logging/demo/ApplicationServiceTest.java
@@ -0,0 +1,45 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.logging
+ * ================================================================================
+ * Copyright © 2018 Amdocs
+ * 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.onap.logging.demo;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Test;
+import org.onap.demo.logging.ApplicationService;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.util.Assert;
+
+public class ApplicationServiceTest {
+
+ @Test
+ public final void testHealth() {
+ ApplicationService service = new ApplicationService();
+ Assert.notNull(service);
+ HttpServletRequest servletRequest = new MockHttpServletRequest();
+ Assert.notNull(servletRequest);
+ boolean health = service.health(servletRequest);
+ Assert.isTrue(health);
+ System.out.println("health : " + health);
+ }
+
+}