From 3145bd4342283e4b52eb25dad4363765fca3d972 Mon Sep 17 00:00:00 2001 From: minjungkim <97938489+pushedrumex@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:22:04 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EB=A1=9C=EA=B7=B8=20aop=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20(#47)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore/#45: 로그 aop 설정 * chore/#45: jacoco 제외 파일 설정 --- build.gradle | 4 +- .../verby/indp/global/aspect/LogAspect.java | 47 +++++++++++++++++++ src/main/resources/server-secrets | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/verby/indp/global/aspect/LogAspect.java diff --git a/build.gradle b/build.gradle index 0bcba3e..90023ae 100644 --- a/build.gradle +++ b/build.gradle @@ -102,7 +102,9 @@ def jacocoExcludePatterns = [ "**/*Filter*", "**/*Resolver*", "**/resources/**", - "**/common/**" + "**/exception/**", + "**/config/**", + "**/aspect/**", ] def excludedClassFilesForReport(classDirectories, jacocoExcludePatterns) { diff --git a/src/main/java/com/verby/indp/global/aspect/LogAspect.java b/src/main/java/com/verby/indp/global/aspect/LogAspect.java new file mode 100644 index 0000000..daa971f --- /dev/null +++ b/src/main/java/com/verby/indp/global/aspect/LogAspect.java @@ -0,0 +1,47 @@ +package com.verby.indp.global.aspect; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Slf4j +@Aspect +@Order(1) +@Component +public class LogAspect { + + @Pointcut("bean(*Service)") + private void allService() { + } + + @Pointcut("bean(*Controller)") + private void allRequest() { + } + + @AfterThrowing(pointcut = "allService()", throwing = "exception") + private void logException(JoinPoint joinPoint, RuntimeException exception) { + String exName = exception.getClass().getSimpleName(); + String exMessage = exception.getMessage(); + String methodName = joinPoint.getSignature().toShortString(); + Object[] args = joinPoint.getArgs(); + + log.warn("[Exception] {} exName=[{}] exMessage=[{}] args=[{}]", + methodName, exName, exMessage, args); + } + + @Around("allRequest()") + private Object logRequest(ProceedingJoinPoint joinPoint) throws Throwable { + String methodName = joinPoint.getSignature().toShortString(); + Object[] args = joinPoint.getArgs(); + + log.info("[Request] {} params=[{}]]", methodName, args); + + return joinPoint.proceed(); + } +} diff --git a/src/main/resources/server-secrets b/src/main/resources/server-secrets index 6c7b3cb..3bbd074 160000 --- a/src/main/resources/server-secrets +++ b/src/main/resources/server-secrets @@ -1 +1 @@ -Subproject commit 6c7b3cb5bf927b072b9320dfd7af8369b6949d6d +Subproject commit 3bbd0741108f7dcb0be1e79b9cb73cf0d29ef77a