diff --git a/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java b/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java index 9c6efdf..55baa6e 100644 --- a/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java +++ b/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java @@ -1,36 +1,32 @@ package cokr.xit.ens.core.aop; -import cokr.xit.ens.core.aop.repository.AccessLogRepository; -import cokr.xit.ens.core.exception.EnsException; -import cokr.xit.ens.core.exception.code.EnsErrCd; -import cokr.xit.ens.core.monitor.slack.event.MonitorEvent; -import cokr.xit.ens.core.utils.CmmnUtil; -import cokr.xit.ens.core.utils.JwtUtil; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; +import java.io.*; +import java.util.*; +import java.util.regex.*; +import java.util.stream.*; + +import javax.servlet.http.*; + +import org.aspectj.lang.*; +import org.aspectj.lang.annotation.*; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; -import java.io.BufferedReader; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; +import org.springframework.boot.autoconfigure.condition.*; +import org.springframework.context.*; +import org.springframework.http.*; +import org.springframework.stereotype.*; +import org.springframework.util.*; +import org.springframework.web.context.request.*; + +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.*; + +import cokr.xit.ens.core.aop.repository.*; +import cokr.xit.ens.core.exception.*; +import cokr.xit.ens.core.exception.code.*; +import cokr.xit.ens.core.monitor.slack.event.*; +import cokr.xit.ens.core.utils.*; +import lombok.*; +import lombok.extern.slf4j.*; /** * @author (주)엑스아이티 개발팀 @@ -59,6 +55,12 @@ public class AccessLogAspect { @Value("${app.access.auth.exclude.uri}") private List EXCLUDE_URIS; + @Value("${app.jpa.logging.param:false}") + private boolean JPA_LOGGING_PARAM; + + @Value("${app.jpa.logging.result:false}") + private boolean JPA_LOGGING_RESULT; + @Pointcut("execution(* cokr.xit..presentation.*Controller.*(..))") public void presentationLayer() { } @@ -368,5 +370,26 @@ public class AccessLogAspect { return false; } + // FIXME: JPA 쿼리 로그 출력 코드 추가 + @ConditionalOnProperty(value = "app.jpa.logging.enabled", havingValue = "true", matchIfMissing = false) + @Around("execution(* org.springframework.data.repository.CrudRepository+.*(..))") + public Object logJpaQuery(ProceedingJoinPoint joinPoint) throws Throwable { + String methodName = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName(); + Object[] args = joinPoint.getArgs(); + + if(JPA_LOGGING_PARAM) + log.info("Executing JPA query - {}\n args: {}", methodName, Arrays.toString(args)); + else + log.info("Executing JPA query - {}", methodName); + + long startTime = System.currentTimeMillis(); + Object result = joinPoint.proceed(); + long endTime = System.currentTimeMillis(); + if(JPA_LOGGING_RESULT) + log.info("JPA query - {} : executed in {} ms\n result: {}", methodName, (endTime - startTime), result); + else + log.info("JPA query - {} : executed in {} ms", methodName, (endTime - startTime)); + return result; + } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 9014d7b..3590eca 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -33,10 +33,10 @@ spring: jpa: database-platform: org.hibernate.dialect.Oracle10gDialect - show-sql: true #하이버네이트SQL 콘솔 출력 여부 - properties: - hibernate: - format_sql: true + # show-sql: true #하이버네이트SQL 콘솔 출력 여부 + # properties: + # hibernate: + # format_sql: true hibernate: ddl-auto: none @@ -71,4 +71,10 @@ contract: xit: mblpage: payinf: - host: ${xit.app.url}${xit.app.ctx} \ No newline at end of file + host: ${xit.app.url}${xit.app.ctx} + +app: + jpa: + logging: + param: true + result: true