From ed6c5001ea38f88a314034c406d46fbc260520c0 Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Thu, 1 Aug 2024 16:07:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20access=20log=20JPA=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../mapper/TcaRlaybsnmManageMapper.java | 26 +++++++ .../service/TrafficCaSigntalkService.java | 20 ++--- .../xit/ens/core/aop/AccessErrorMessage.java | 18 ++--- .../xit/ens/core/aop/AccessLogAspect.java | 77 +++++++++---------- .../aop/{AccessLog.java => AccessLogDTO.java} | 40 +++------- .../xit/ens/core/aop/AccessLogService.java | 39 ++++++++++ .../ens/core/aop/mapper/IAccessLogMapper.java | 11 +++ .../aop/repository/AccessLogRepository.java | 8 -- .../ens/core/config/logging/P6SpyConfig.java | 17 ++-- .../core/config/logging/P6SpyFormatter.java | 24 +++--- .../config/logging/P6spyLoggingConfig.java | 20 ----- .../cokr/xit/ens/modules/IndexController.java | 7 +- src/main/resources/application.yml | 4 +- src/main/resources/config/conf-log.yml | 2 +- .../mybatis-mapper/core/AccessLogMapper.xml | 43 +++++++++++ 16 files changed, 220 insertions(+), 138 deletions(-) create mode 100644 src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/mapper/TcaRlaybsnmManageMapper.java rename src/main/java/cokr/xit/ens/core/aop/{AccessLog.java => AccessLogDTO.java} (62%) create mode 100644 src/main/java/cokr/xit/ens/core/aop/AccessLogService.java create mode 100644 src/main/java/cokr/xit/ens/core/aop/mapper/IAccessLogMapper.java delete mode 100644 src/main/java/cokr/xit/ens/core/aop/repository/AccessLogRepository.java delete mode 100644 src/main/java/cokr/xit/ens/core/config/logging/P6spyLoggingConfig.java create mode 100644 src/main/resources/mybatis-mapper/core/AccessLogMapper.xml diff --git a/pom.xml b/pom.xml index fa8564f..ec3c749 100644 --- a/pom.xml +++ b/pom.xml @@ -179,7 +179,7 @@ com.github.gavlyukovskiy p6spy-spring-boot-starter - 1.8.0 + 1.8.1 diff --git a/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/mapper/TcaRlaybsnmManageMapper.java b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/mapper/TcaRlaybsnmManageMapper.java new file mode 100644 index 0000000..442dfdc --- /dev/null +++ b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/mapper/TcaRlaybsnmManageMapper.java @@ -0,0 +1,26 @@ +// package cokr.xit.ens.biz.traffic.cheonan.signtalk.mapper; +// +// import org.apache.ibatis.annotations.Delete; +// import org.apache.ibatis.annotations.Insert; +// import org.apache.ibatis.annotations.Mapper; +// import org.apache.ibatis.annotations.Param; +// import org.apache.ibatis.annotations.Select; +// import org.apache.ibatis.annotations.Update; +// +// import cokr.xit.ens.biz.traffic.cheonan.signtalk.dto.TcaRlaybsnmManageDTO; +// +// @Mapper +// public interface TcaRlaybsnmManageMapper { +// +// @Select("SELECT * FROM TCA_RLAYBSNM_MANAGE WHERE id = #{id}") +// TcaRlaybsnmManageDTO findById(@Param("id") String id); +// +// @Insert("INSERT INTO TCA_RLAYBSNM_MANAGE (id, ...) VALUES (#{id}, ...)") +// void insert(TcaRlaybsnmManageDTO dto); +// +// @Update("UPDATE TCA_RLAYBSNM_MANAGE SET ... WHERE id = #{id}") +// void update(TcaRlaybsnmManageDTO dto); +// +// @Delete("DELETE FROM TCA_RLAYBSNM_MANAGE WHERE id = #{id}") +// void deleteById(@Param("id") String id); +// } diff --git a/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java index a58e762..0553480 100644 --- a/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java +++ b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java @@ -1,5 +1,14 @@ package cokr.xit.ens.biz.traffic.cheonan.signtalk.service; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import cokr.xit.ens.biz.traffic.cheonan.code.SndngProcessSttusCd; import cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.TcaElctrnNticSndng; import cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.repository.TcaElctrnNticSndngRepository; @@ -14,14 +23,6 @@ import cokr.xit.ens.core.utils.CmmnUtil; import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.event.IntgrnNotiSendReserveEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; @Slf4j @Service @@ -42,10 +43,11 @@ public class TrafficCaSigntalkService { /** * 인증톡 접수(TRAFFIC -> ENS) */ + @Transactional(readOnly = true) public EnsResponseVO accept(String elctrnNticSndngId) { try { - + TcaElctrnNticSndng elctrnNticSndng = tcaElctrnNticSndngRepository.findById(elctrnNticSndngId) .orElseThrow(() -> new EnsException(EnsErrCd.ACPT404, "일치하는 자료가 없습니다.")); if (!SndngProcessSttusCd.accept.equals(elctrnNticSndng.getSndngProcessSttus())) diff --git a/src/main/java/cokr/xit/ens/core/aop/AccessErrorMessage.java b/src/main/java/cokr/xit/ens/core/aop/AccessErrorMessage.java index 051984c..c6bfd08 100644 --- a/src/main/java/cokr/xit/ens/core/aop/AccessErrorMessage.java +++ b/src/main/java/cokr/xit/ens/core/aop/AccessErrorMessage.java @@ -1,17 +1,17 @@ package cokr.xit.ens.core.aop; -import cokr.xit.ens.core.utils.CmmnUtil; -import cokr.xit.ens.core.monitor.Message; -import lombok.Builder; - import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import cokr.xit.ens.core.monitor.Message; +import cokr.xit.ens.core.utils.CmmnUtil; +import lombok.Builder; + @Builder public class AccessErrorMessage implements Message { private final String ACTIVE_PROFILE; - private final AccessLog accessLog; + private final AccessLogDTO accessLogDTO; private final String serverUrl; public String create() { @@ -27,11 +27,11 @@ public class AccessErrorMessage implements Message { .append("[Occurrence time]: ") .append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))) .append(System.getProperty("line.separator")) - .append("[Client Ip]: " + accessLog.getIp()) + .append("[Client Ip]: " + accessLogDTO.getIp()) .append(System.getProperty("line.separator")) - .append("[Request Url]: " + accessLog.getHttpMethod() + " " + accessLog.getUrl()) + .append("[Request Url]: " + accessLogDTO.getHttpMethod() + " " + accessLogDTO.getUrl()) .append(System.getProperty("line.separator")) - .append("[Request Param]: " + accessLog.getParam()) + .append("[Request Param]: " + accessLogDTO.getParam()) .append(System.getProperty("line.separator")) // .append("[Details]: ") // .append(accessLog.getErrorMsg()) @@ -39,7 +39,7 @@ public class AccessErrorMessage implements Message { .append(System.getProperty("line.separator")) .append("[StackTrace]:") .append(System.getProperty("line.separator")) - .append(accessLog.getErrorMsg()); + .append(accessLogDTO.getErrorMsg()); return sb.toString(); } 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..069671c 100644 --- a/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java +++ b/src/main/java/cokr/xit/ens/core/aop/AccessLogAspect.java @@ -1,15 +1,15 @@ 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 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 javax.servlet.http.HttpServletRequest; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -23,14 +23,16 @@ 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 com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +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 lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** * @author (주)엑스아이티 개발팀 @@ -51,7 +53,7 @@ public class AccessLogAspect { @Value("${spring.profiles.active}") private String ACTIVE_PROFILE; - private final AccessLogRepository accessLogRepository; + private final AccessLogService accessLogService; private final String ACCESS_TOKEN_NAME = "Authorization"; private final ApplicationEventPublisher applicationEventPublisher; @@ -88,14 +90,12 @@ public class AccessLogAspect { long start = System.currentTimeMillis(); Object result = null; - AccessLog accessLog = null; + AccessLogDTO accessLogDTO = null; try { log.info("[BEFORE] : ..."); - accessLog = this.setRequestInfo(request); - accessLogRepository.save(accessLog); - - + accessLogDTO = this.setRequestInfo(request); + accessLogService.save(accessLogDTO); if (this.isCertified(request)) { @@ -103,8 +103,8 @@ public class AccessLogAspect { log.info("[AFTER] : ..."); - this.setResponseInfo(accessLog, result); - accessLogRepository.save(accessLog); + this.setResponseInfo(accessLogDTO, result); + accessLogService.save(accessLogDTO); } else { @@ -117,16 +117,15 @@ public class AccessLogAspect { log.error(String.format("[NoAuth] : %s => %s", ACCESS_TOKEN_NAME, request.getHeader(ACCESS_TOKEN_NAME))); - accessLog.setResponseNoAuth(msg); - accessLogRepository.save(accessLog); - + accessLogDTO.setResponseNoAuth(msg); + accessLogService.save(accessLogDTO); } } catch (EnsException e) { log.error(String.format("[ERROR] : %s", e.getMessage())); - accessLog.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage())); - accessLogRepository.save(accessLog); + accessLogDTO.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage())); + accessLogService.save(accessLogDTO); if (result == null) { EnsResponseVO restResponseVO = EnsResponseVO .errBuilder() @@ -138,8 +137,8 @@ public class AccessLogAspect { } catch (Exception e) { log.error(String.format("[%s ERROR] : %s", EnsErrCd.UNKNOWN, e.getMessage()), e); - accessLog.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e))); - accessLogRepository.save(accessLog); + accessLogDTO.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e))); + accessLogService.save(accessLogDTO); if (result == null) { EnsResponseVO restResponseVO = EnsResponseVO .errBuilder() @@ -150,7 +149,7 @@ public class AccessLogAspect { applicationEventPublisher.publishEvent(MonitorEvent.builder() - .message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLog(accessLog).serverUrl(CmmnUtil.getServerUrl()).build()) + .message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLogDTO(accessLogDTO).serverUrl(CmmnUtil.getServerUrl()).build()) .build()); } @@ -174,7 +173,7 @@ public class AccessLogAspect { * @date: 2021. 11. 30. */ @SuppressWarnings("deprecation") - private AccessLog setRequestInfo(HttpServletRequest request) throws JsonProcessingException { + private AccessLogDTO setRequestInfo(HttpServletRequest request) throws JsonProcessingException { String sessionId = request.getSession().getId(); String param = null; try { @@ -185,7 +184,7 @@ public class AccessLogAspect { param = String.format("[요청 parameter 변환 실패]: %s", e.getMessage()); } - return AccessLog.reqBuilder() + return AccessLogDTO.reqBuilder() .accessToken(request.getHeader(ACCESS_TOKEN_NAME)) .sessionId(sessionId) .ip(this.getClientIpAddr(request)) @@ -199,12 +198,12 @@ public class AccessLogAspect { /** *
메소드 설명: 응답정보 설정
* - * @param accessLog + * @param accessLogDTO * @param result * @author: 박민규 * @date: 2021. 11. 30. */ - private void setResponseInfo(AccessLog accessLog, Object result) { + private void setResponseInfo(AccessLogDTO accessLogDTO, Object result) { String response = null; if (result instanceof String) response = (String) result; @@ -215,7 +214,7 @@ public class AccessLogAspect { else response = String.valueOf(result); - accessLog.setResponseCompleted(response); + accessLogDTO.setResponseCompleted(response); } diff --git a/src/main/java/cokr/xit/ens/core/aop/AccessLog.java b/src/main/java/cokr/xit/ens/core/aop/AccessLogDTO.java similarity index 62% rename from src/main/java/cokr/xit/ens/core/aop/AccessLog.java rename to src/main/java/cokr/xit/ens/core/aop/AccessLogDTO.java index e6a34c3..0a64ef5 100644 --- a/src/main/java/cokr/xit/ens/core/aop/AccessLog.java +++ b/src/main/java/cokr/xit/ens/core/aop/AccessLogDTO.java @@ -1,28 +1,15 @@ package cokr.xit.ens.core.aop; -import cokr.xit.ens.core.aop.code.AccessStatusCd; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.UpdateTimestamp; - -import javax.persistence.*; import java.time.LocalDateTime; -@Entity -@Getter -@RequiredArgsConstructor -@Table(name = "ens_access_log", schema = "", catalog = "") -public class AccessLog { - +import cokr.xit.ens.core.aop.code.AccessStatusCd; +import lombok.Builder; +import lombok.Data; - @Id - @GeneratedValue(strategy = GenerationType.AUTO) +@Data +public class AccessLogDTO { private Long logId; - @Column(length = 2000) private String accessToken; private String reqSystemId; @@ -37,27 +24,22 @@ public class AccessLog { private String uri; - @Lob private String param; - @Lob + private String response; - - @Enumerated(EnumType.STRING) + private AccessStatusCd status; - - @Lob + private String errorMsg; - - @CreationTimestamp + private LocalDateTime startDt; - - @UpdateTimestamp + private LocalDateTime endDt; @Builder(builderClassName = "reqBuilder", builderMethodName = "reqBuilder") - public AccessLog(String accessToken, String sessionId, String ip, String httpMethod, String url, String uri, String param) { + public AccessLogDTO(String accessToken, String sessionId, String ip, String httpMethod, String url, String uri, String param) { this.accessToken = accessToken; this.sessionId = sessionId; this.ip = ip; diff --git a/src/main/java/cokr/xit/ens/core/aop/AccessLogService.java b/src/main/java/cokr/xit/ens/core/aop/AccessLogService.java new file mode 100644 index 0000000..d8a6618 --- /dev/null +++ b/src/main/java/cokr/xit/ens/core/aop/AccessLogService.java @@ -0,0 +1,39 @@ +package cokr.xit.ens.core.aop; + +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import cokr.xit.ens.core.aop.mapper.IAccessLogMapper; +import lombok.RequiredArgsConstructor; + +/** + *
+ * description : 
+ * packageName : cokr.xit.ens.core.aop
+ * fileName    : AccessLogService
+ * author      : limju
+ * date        : 2024-08-01
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-08-01   limju       최초 생성
+ *
+ * 
+ */ +@Service +@RequiredArgsConstructor +public class AccessLogService { + // private final AccessLogRepository accessLogRepository; + private final IAccessLogMapper accessLogMapper; + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void save(AccessLogDTO accessLogDTO) { + if(ObjectUtils.isEmpty(accessLogDTO.getLogId())) { + accessLogMapper.insertAccessLog(accessLogDTO); + }else{ + accessLogMapper.updateAccessLog(accessLogDTO); + } + } +} diff --git a/src/main/java/cokr/xit/ens/core/aop/mapper/IAccessLogMapper.java b/src/main/java/cokr/xit/ens/core/aop/mapper/IAccessLogMapper.java new file mode 100644 index 0000000..025ddba --- /dev/null +++ b/src/main/java/cokr/xit/ens/core/aop/mapper/IAccessLogMapper.java @@ -0,0 +1,11 @@ +package cokr.xit.ens.core.aop.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import cokr.xit.ens.core.aop.AccessLogDTO; + +@Mapper +public interface IAccessLogMapper { + int insertAccessLog(AccessLogDTO accessLogDTO); + int updateAccessLog(AccessLogDTO accessLogDTO); +} diff --git a/src/main/java/cokr/xit/ens/core/aop/repository/AccessLogRepository.java b/src/main/java/cokr/xit/ens/core/aop/repository/AccessLogRepository.java deleted file mode 100644 index ebc1e90..0000000 --- a/src/main/java/cokr/xit/ens/core/aop/repository/AccessLogRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package cokr.xit.ens.core.aop.repository; - -import cokr.xit.ens.core.aop.AccessLog; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AccessLogRepository extends JpaRepository{ - -} diff --git a/src/main/java/cokr/xit/ens/core/config/logging/P6SpyConfig.java b/src/main/java/cokr/xit/ens/core/config/logging/P6SpyConfig.java index 4cfe052..c8e138b 100644 --- a/src/main/java/cokr/xit/ens/core/config/logging/P6SpyConfig.java +++ b/src/main/java/cokr/xit/ens/core/config/logging/P6SpyConfig.java @@ -6,12 +6,17 @@ import org.springframework.context.annotation.Configuration; @Configuration public class P6SpyConfig { - @Bean - public P6SpyEventListener p6SpyCustomEventListener() { - return new P6SpyEventListener(); - } @Bean - public P6SpyFormatter p6SpyCustomFormatter() { - return new P6SpyFormatter(); + public P6SpyEventListener p6SpyCustomEventListener() { + return new P6SpyEventListener(); } + @Bean + public P6SpyFormatter p6SpyCustomFormatter() { + return new P6SpyFormatter(); + } + + // @PostConstruct + // public void setLogMessageFormat() { + // P6SpyOptions.getActiveInstance().setLogMessageFormat(P6SpyFormatter.class.getName()); + // } } diff --git a/src/main/java/cokr/xit/ens/core/config/logging/P6SpyFormatter.java b/src/main/java/cokr/xit/ens/core/config/logging/P6SpyFormatter.java index 8ad67c2..36450b6 100644 --- a/src/main/java/cokr/xit/ens/core/config/logging/P6SpyFormatter.java +++ b/src/main/java/cokr/xit/ens/core/config/logging/P6SpyFormatter.java @@ -17,24 +17,27 @@ public class P6SpyFormatter implements MessageFormattingStrategy { private static final String ALTER = "alter"; private static final String DROP = "drop"; private static final String COMMENT = "comment"; - private static final String COMMIT = "commit"; @Override public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { - if(category.equals(COMMIT)) return "Connection ID: " + connectionId + " " + COMMIT; - if (sql.trim().isEmpty()) { - return formatByCommand(category); + if (sql == null || sql.trim().isEmpty()) { + return formatByCommand(connectionId, category); } - return formatBySql(sql, category) + getAdditionalMessages(connectionId, elapsed); + return "\n----------------------------------------------------------------------------------------------------\n" + + "Execute DML : \n" + + TAP + TAP + + sql + ";" + + getAdditionalMessages(connectionId, elapsed); + + //return formatBySql(sql, category) + getAdditionalMessages(connectionId, elapsed); } - private static String formatByCommand(String category) { + private static String formatByCommand(int connectionId, String category) { return NEW_LINE + + "----------------------------------------------------------------------------------------------------\n" + "Execute Command : " + NEW_LINE - + NEW_LINE + TAP - + category - + NEW_LINE + + category + ", Connection ID - " + connectionId + NEW_LINE + "----------------------------------------------------------------------------------------------------"; } @@ -48,6 +51,7 @@ public class P6SpyFormatter implements MessageFormattingStrategy { .format(sql); } return NEW_LINE + + "----------------------------------------------------------------------------------------------------\n" + "Execute DML : " + NEW_LINE + FormatStyle.BASIC @@ -57,7 +61,7 @@ public class P6SpyFormatter implements MessageFormattingStrategy { private String getAdditionalMessages(int connectionId, long elapsed) { return NEW_LINE + NEW_LINE - + String.format("Connection ID: %s Execution Time: %s ms", connectionId, elapsed) + + String.format("Execution Time: %s ms, Connection ID - %s", elapsed, connectionId) + NEW_LINE + "----------------------------------------------------------------------------------------------------"; } diff --git a/src/main/java/cokr/xit/ens/core/config/logging/P6spyLoggingConfig.java b/src/main/java/cokr/xit/ens/core/config/logging/P6spyLoggingConfig.java deleted file mode 100644 index cb3cc20..0000000 --- a/src/main/java/cokr/xit/ens/core/config/logging/P6spyLoggingConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package cokr.xit.ens.core.config.logging; - -import javax.annotation.PostConstruct; - -import org.springframework.context.annotation.Configuration; - -import com.p6spy.engine.spy.P6SpyOptions; - -@Configuration -public class P6spyLoggingConfig { - - /** - * JPA SQL Logging - * decorator.datasource.p6spy.enable-logging: true / false - */ - @PostConstruct - public void setLogMessageFormat() { - P6SpyOptions.getActiveInstance().setLogMessageFormat(P6SpyFormatter.class.getName()); - } -} diff --git a/src/main/java/cokr/xit/ens/modules/IndexController.java b/src/main/java/cokr/xit/ens/modules/IndexController.java index 7cee2e5..ce40b8f 100644 --- a/src/main/java/cokr/xit/ens/modules/IndexController.java +++ b/src/main/java/cokr/xit/ens/modules/IndexController.java @@ -1,18 +1,17 @@ package cokr.xit.ens.modules; -import cokr.xit.ens.core.aop.repository.AccessLogRepository; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + import cokr.xit.ens.core.code.CodeMapperFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; @Slf4j @Controller @RequiredArgsConstructor public class IndexController { - private final AccessLogRepository accessLogRepository; private final CodeMapperFactory codeMapperFactory; @GetMapping("/") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f616185..e1f0a1a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -59,7 +59,7 @@ spring: jpa: database-platform: org.hibernate.dialect.MariaDB103Dialect - # show-sql: true + show-sql: true # generate-ddl: true #TODO: 필요 시 주석해제. generate-ddl를 true 설정 시 ddl-auto의 설정값과 무관하게 DDL 스크립트 실행 hibernate: ddl-auto: none @@ -68,7 +68,7 @@ spring: physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy properties: hibernate: - # format_sql: true + format_sql: true # use_sql_comments: true order_inserts: true order_updates: true diff --git a/src/main/resources/config/conf-log.yml b/src/main/resources/config/conf-log.yml index fb5841b..02fe8df 100644 --- a/src/main/resources/config/conf-log.yml +++ b/src/main/resources/config/conf-log.yml @@ -15,7 +15,7 @@ logging: file: utf-8 level: root: info - '[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력 + #'[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력 # '[org.springframework.orm.jpa]': debug # '[org.springframework.transaction]': debug # '[org.springframework.transaction.interceptor]': trace diff --git a/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml b/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml new file mode 100644 index 0000000..36a39c7 --- /dev/null +++ b/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml @@ -0,0 +1,43 @@ + + + + + + + SELECT nextval(hibernate_sequence) + + INSERT INTO ens_access_log ( + log_id, + access_token, + http_method, + ip, + param, + req_system_id, + session_id, + start_dt, + status, + uri, + url + ) VALUES ( + #{logId}, + #{accessToken}, + #{httpMethod}, + #{ip}, + #{param}, + #{reqSystemId}, + #{sessionId}, + now(), + #{status}, + #{uri}, + #{url} + ) + + + + UPDATE ens_access_log + SET end_dt = now() + , status = #{status} + WHERE log_id = #{logId} + + + From c14cdee5044a5e7c0f25a688d37a88a4a1d3e10e Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Thu, 1 Aug 2024 16:31:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20access=20log=20JPA=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheonan/signtalk/service/TrafficCaSigntalkService.java | 1 - src/main/resources/mybatis-mapper/core/AccessLogMapper.xml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java index 0553480..9a00268 100644 --- a/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java +++ b/src/main/java/cokr/xit/ens/biz/traffic/cheonan/signtalk/service/TrafficCaSigntalkService.java @@ -47,7 +47,6 @@ public class TrafficCaSigntalkService { public EnsResponseVO accept(String elctrnNticSndngId) { try { - TcaElctrnNticSndng elctrnNticSndng = tcaElctrnNticSndngRepository.findById(elctrnNticSndngId) .orElseThrow(() -> new EnsException(EnsErrCd.ACPT404, "일치하는 자료가 없습니다.")); if (!SndngProcessSttusCd.accept.equals(elctrnNticSndng.getSndngProcessSttus())) diff --git a/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml b/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml index 36a39c7..d3b0fc1 100644 --- a/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml +++ b/src/main/resources/mybatis-mapper/core/AccessLogMapper.xml @@ -37,6 +37,7 @@ UPDATE ens_access_log SET end_dt = now() , status = #{status} + , response = #{response} WHERE log_id = #{logId}