feat: JPA query 로깅 추가

main
Jonguk. Lim 2 months ago
parent bc70be8695
commit 8740a8c6fc

@ -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<String> 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;
}
}

@ -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}
host: ${xit.app.url}${xit.app.ctx}
app:
jpa:
logging:
param: true
result: true

Loading…
Cancel
Save