LoggerAspect
페이지 정보
본문
[소스 내용]
package web.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import lombok.extern.log4j.Log4j2;
@Component //개발자가 직접 작성한 Class를 객체(Bean)로 등록 가능하게 하는 기능
@Aspect //AOP 설정 기능
@Log4j2 //log 사용 기능
public class LoggerAspect {
//@Around(해당 메서드 실행 전,후) : 어드바이스가 타겟 메서드를 감싸서 호출 전과 후 어드바이스 기능 수행
//execution : 포인트컷 표현식으로 적용
//web.. : ..의 의미는 0개 이상 뜻, 파라미터, 메서드, 패키지 등 모든 것을 의미
@Around("execution(* web..controller.*Controller.*(..)) or "
+ "execution(* web..service.*Impl.*(..)) or "
+ "execution(* web..mapper.*Mapper.*(..))")
public Object logPrint(ProceedingJoinPoint joinPoint) throws Throwable {
String type = "";
String name = joinPoint.getSignature().getDeclaringTypeName();
//indexOf(String str) : 발견되는 인덱스 값을 반환한다. 찾지 못하면 -1 반환한다.
if(name.indexOf("Controller") > -1) {
type = "=== Controller : ";
}else if(name.indexOf("Impl") > -1) {
type = "=== Impl : ";
}else if(name.indexOf("Mapper") > -1) {
type = "=== Mapper : ";
}
log.debug(type + name + "." + joinPoint.getSignature().getName() + "()"); //콘솔 출력
return joinPoint.proceed();
}
}
- 이전글■ AOP 정의 ( 콘솔에서 확인 ) 24.06.11
- 다음글■ 인터셉터 사용하기 ( 콘솔에서 확인 ) 24.06.11
댓글목록
등록된 댓글이 없습니다.