2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
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.oransc.policyagent.aspect;
23 import org.aspectj.lang.JoinPoint;
24 import org.aspectj.lang.ProceedingJoinPoint;
25 import org.aspectj.lang.annotation.After;
26 import org.aspectj.lang.annotation.Around;
27 import org.aspectj.lang.annotation.Aspect;
28 import org.aspectj.lang.annotation.Before;
29 import org.aspectj.lang.reflect.MethodSignature;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Component;
33 import org.springframework.util.StopWatch;
37 public class LogAspect {
39 private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
41 @Around("execution(* org.oransc.policyagent..*(..)))")
42 public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
43 MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
44 String className = methodSignature.getDeclaringType().getSimpleName();
45 String methodName = methodSignature.getName();
46 final StopWatch stopWatch = new StopWatch();
48 proceedingJoinPoint.proceed();
50 logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
53 @Before("execution(* org.oransc.policyagent..*(..)))")
54 public void entryLog(final JoinPoint joinPoint) throws Throwable {
55 logger.trace("Entering method: {}", joinPoint.getSignature().getName());
58 @After("execution(* org.oransc.policyagent..*(..)))")
59 public void exitLog(final JoinPoint joinPoint) throws Throwable {
60 logger.trace("Exiting method: {}", joinPoint.getSignature().getName());