From: John Keeney Date: Fri, 20 Mar 2020 18:18:06 +0000 (+0000) Subject: Merge "Spring Aspect logging" X-Git-Tag: 2.0.0~107 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=61fcee9bad6d96005c403fdfd3f273430d4f8641;hp=290048d657c9e161133a84b043e33a6c6219b6b0;p=nonrtric.git Merge "Spring Aspect logging" --- diff --git a/policy-agent/config/application.yaml b/policy-agent/config/application.yaml index 9fb3fba5..f0fa3a0a 100644 --- a/policy-agent/config/application.yaml +++ b/policy-agent/config/application.yaml @@ -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: diff --git a/policy-agent/pom.xml b/policy-agent/pom.xml index b8dcbc47..f718d0ba 100644 --- a/policy-agent/pom.xml +++ b/policy-agent/pom.xml @@ -75,6 +75,10 @@ org.springframework.boot spring-boot-starter-webflux + + org.springframework.boot + spring-boot-starter-aop + org.springframework.boot spring-boot-devtools 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 index 00000000..f4419b76 --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/aspect/LogAspect.java @@ -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()); + } + +}