1c40f04fdd02b2909666bbfe4245544f17adc932
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.aspect;
22
23 import java.lang.invoke.MethodHandles;
24
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;
36
37 @Aspect
38 @Component
39 public class LogAspect {
40
41     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
42
43     @Around("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
44     public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
45         final StopWatch stopWatch = new StopWatch();
46         stopWatch.start();
47         proceedingJoinPoint.proceed();
48         stopWatch.stop();
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());
53     }
54
55     @Before("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
56     public void entryLog(final JoinPoint joinPoint) {
57         logger.trace("Entering method: {}", joinPoint.getSignature().getName());
58     }
59
60     @After("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))")
61     public void exitLog(final JoinPoint joinPoint) {
62         logger.trace("Exiting method: {}", joinPoint.getSignature().getName());
63     }
64
65 }