2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2020 Nordix Foundation. All rights reserved.
6 * ======================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.aspect;
23 import java.lang.invoke.MethodHandles;
25 import org.aspectj.lang.JoinPoint;
26 import org.aspectj.lang.ProceedingJoinPoint;
27 import org.aspectj.lang.annotation.After;
28 import org.aspectj.lang.annotation.Around;
29 import org.aspectj.lang.annotation.Aspect;
30 import org.aspectj.lang.annotation.Before;
31 import org.aspectj.lang.reflect.MethodSignature;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.stereotype.Component;
35 import org.springframework.util.StopWatch;
39 public class LogAspect {
41 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
43 @Around("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
44 public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
45 final StopWatch stopWatch = new StopWatch();
47 proceedingJoinPoint.proceed();
49 MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
50 String className = methodSignature.getDeclaringType().getSimpleName();
51 String methodName = methodSignature.getName();
52 logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
55 @Before("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
56 public void entryLog(final JoinPoint joinPoint) {
57 logger.trace("Entering method: {}", joinPoint.getSignature().getName());
60 @After("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
61 public void exitLog(final JoinPoint joinPoint) {
62 logger.trace("Exiting method: {}", joinPoint.getSignature().getName());