Merge "Added STD sim 2.0.0 tests"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / aspect / LogAspect.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2020 Nordix Foundation
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.oransc.policyagent.aspect;
22
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;
34
35 @Aspect
36 @Component
37 public class LogAspect {
38
39     private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
40
41     @Around("execution(* org.oransc.policyagent..*(..)))")
42     public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
43         final StopWatch stopWatch = new StopWatch();
44         stopWatch.start();
45         proceedingJoinPoint.proceed();
46         stopWatch.stop();
47         MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
48         String className = methodSignature.getDeclaringType().getSimpleName();
49         String methodName = methodSignature.getName();
50         logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
51     }
52
53     @Before("execution(* org.oransc.policyagent..*(..)))")
54     public void entryLog(final JoinPoint joinPoint) {
55         logger.trace("Entering method: {}", joinPoint.getSignature().getName());
56     }
57
58     @After("execution(* org.oransc.policyagent..*(..)))")
59     public void exitLog(final JoinPoint joinPoint) {
60         logger.trace("Exiting method: {}", joinPoint.getSignature().getName());
61     }
62
63 }