Merge "Spring Aspect logging"
authorJohn Keeney <John.Keeney@est.tech>
Fri, 20 Mar 2020 18:18:06 +0000 (18:18 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Fri, 20 Mar 2020 18:18:06 +0000 (18:18 +0000)
policy-agent/config/application.yaml
policy-agent/pom.xml
policy-agent/src/main/java/org/oransc/policyagent/aspect/LogAspect.java [new file with mode: 0644]

index 9fb3fba..f0fa3a0 100644 (file)
@@ -2,7 +2,9 @@ spring:
   profiles:
     active: prod
   main:
-    allow-bean-definition-overriding: true 
+    allow-bean-definition-overriding: true
+  aop:
+    auto: false
 management:
   endpoints:
     web:
index b8dcbc4..f718d0b 100644 (file)
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-webflux</artifactId>
         </dependency>
+        <dependency>
+         <groupId>org.springframework.boot</groupId>
+         <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/aspect/LogAspect.java b/policy-agent/src/main/java/org/oransc/policyagent/aspect/LogAspect.java
new file mode 100644 (file)
index 0000000..f4419b7
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
+ * 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.oransc.policyagent.aspect;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StopWatch;
+
+@Aspect
+@Component
+public class LogAspect {
+
+    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
+
+    @Around("execution(* org.oransc.policyagent..*(..)))")
+    public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+        MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
+        String className = methodSignature.getDeclaringType().getSimpleName();
+        String methodName = methodSignature.getName();
+        final StopWatch stopWatch = new StopWatch();
+        stopWatch.start();
+        proceedingJoinPoint.proceed();
+        stopWatch.stop();
+        logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
+    }
+
+    @Before("execution(* org.oransc.policyagent..*(..)))")
+    public void entryLog(final JoinPoint joinPoint) throws Throwable {
+        logger.trace("Entering method: {}", joinPoint.getSignature().getName());
+    }
+
+    @After("execution(* org.oransc.policyagent..*(..)))")
+    public void exitLog(final JoinPoint joinPoint) throws Throwable {
+        logger.trace("Exiting method: {}", joinPoint.getSignature().getName());
+    }
+
+}