feat: 시스템별 logging 적용

dev
gitea-관리자 1 year ago
parent d864e23fc9
commit d97a9ca935

@ -18,6 +18,7 @@ import kr.xit.core.support.slack.SlackWebhookPush;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.JsonUtils;
import kr.xit.core.support.utils.LogUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
@ -86,8 +87,6 @@ public class TraceLoggerAspect {
private final ILoggingService loggingService;
private final SlackWebhookPush slackWebhookPush;
private static final String MESSAGE = "message";
private static final String CODE = "code";
private static final String REQUEST_TRACE_ID = "request_trace_id";
public TraceLoggerAspect(@Lazy ILoggingService loggingService, SlackWebhookPush slackWebhookPush) {
@ -112,8 +111,8 @@ public class TraceLoggerAspect {
if(!isReqLogEnabled) return;
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes != null? attributes.getRequest(): null;
assert request != null;
requestLog(request, getParams(request));
log.info("Before: " + joinPoint.getSignature().getName());
}
@Around(value = "@annotation(kr.xit.core.spring.annotation.TraceLogging)")
@ -126,8 +125,8 @@ public class TraceLoggerAspect {
traceLogging(JsonUtils.toObjByObj(pjp.getArgs()[0], JSONObject.class), request);
Object result = pjp.proceed();
if(result instanceof CompletableFuture){
CompletableFuture future = (CompletableFuture)result;
//noinspection rawtypes
if(result instanceof CompletableFuture future){
while(true) {
if (future.isDone()) break;
@ -157,12 +156,13 @@ public class TraceLoggerAspect {
/**
* set MDC batch reading , tasklet set trace_id set
* @param params
* @param request
* @param json JSONObject
* @param request HttpServletRequest
*/
protected void traceLogging(final JSONObject json, final HttpServletRequest request) {
String uri = "";
if(request != null) {
String uri = request.getRequestURI();
uri = request.getRequestURI();
if(Arrays.stream(excludes).anyMatch(uri::matches)) return;
MDC.put(REQUEST_TRACE_ID,
@ -180,15 +180,16 @@ public class TraceLoggerAspect {
//TODO::systemId, reqSystemId 설정 필요
log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
String params = resetJsonMasking(json);
String systemId = Checks.isNotEmpty(uri)? ApiSystemId.compareByUri(uri).getCode(): ApiSystemId.valueOf("NONE").getCode();
MDC.put("systemId", "ENS");
MDC.put("reqSystemId", "KAKAO");
MDC.put("reqSystemId", systemId);
MDC.put("param", params);
MDC.put("accessToken", "");
LoggingDTO loggingDTO = LoggingDTO.builder()
.requestId(MDC.getCopyOfContextMap().get(REQUEST_TRACE_ID))
.systemId("ENS")
.reqSystemId("KAKAO")
.reqSystemId(systemId)
.method(MDC.getCopyOfContextMap().get("method"))
.uri(MDC.getCopyOfContextMap().get("uri"))
.param(params)
@ -203,8 +204,8 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
protected void traceLoggingResult(final Object result) {
String success = "true";
//FIXME: slack webhook log push
if(result instanceof ApiResponseDTO<?>){
ApiResponseDTO<?> apiResponseDTO = (ApiResponseDTO<?>)result;
if(result instanceof ApiResponseDTO<?> apiResponseDTO){
if(!apiResponseDTO.isSuccess()){
success = "false";
@ -217,7 +218,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
}else{
slackWebhookPush.sendSlackAlertLog(
String.format("[%s]%s", MDC.get(REQUEST_TRACE_ID), apiResponseDTO.getMessage()),
MDC.get("uri"),
MDC.getCopyOfContextMap().get("uri"),
"batch call");
}
}
@ -247,9 +248,9 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
}
private String getResult(final Object o){
if(o instanceof Future) {
//noinspection rawtypes
if(o instanceof Future future) {
try {
Future<?> future = (Future<?>)o;
return JsonUtils.toJson(future.get());
} catch (InterruptedException ie){
// thread pool에 에러 상태 전송
@ -369,4 +370,32 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
}
return json.toJSONString();
}
@Getter
private enum ApiSystemId {
KAKAO("KAKAO", "카카오", "/kakao/"),
KT_BC("KT-BC", "공공알림문자", "/kt/"),
PPLUS("POST-PLUS", "Post Plus", "/pplus/"),
NICE("NICE", "NICE CI", "/nice/"),
EPOST("EPOST", "E-POST", "/ag/"),
BATCH("BATCH", "미정의", "/미정의/"),
;
private final String code;
private final String desc;
private final String uri;
ApiSystemId(final String code, final String desc, final String uri) {
this.code = code;
this.desc = desc;
this.uri = uri;
}
public static ApiSystemId compareByUri(final String uri){
return Arrays.stream(ApiSystemId.values())
.filter(ssc -> uri.contains(ssc.getUri()))
.findFirst()
.orElseGet(() -> ApiSystemId.valueOf("BATCH"));
}
}
}

@ -40,7 +40,7 @@ public class SndngSendBulksTasklet implements Tasklet {
try {
MDC.put("request_trace_batch_id", UUID.randomUUID().toString().replace("-", ""));
MDC.put("uri", "/v1/documents/bulk");
//MDC.put("uri", "/v1/documents/bulk");
MDC.put("method", "POST");
service.sendBulks(

@ -40,7 +40,7 @@ public class SndngStatusBulksTasklet implements Tasklet {
try {
MDC.put("request_trace_batch_id", UUID.randomUUID().toString().replace("-", ""));
MDC.put("uri", "/v1/documents/bulk/status");
//MDC.put("uri", "/v1/documents/bulk/status");
MDC.put("method", "POST");
service.statusBulks(

@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
@Tag(name = " SmsMessageController", description = "SMS(xit) 연계 서비스")
@RequiredArgsConstructor
@RestController
@RequestMapping("/batch/ens/v1")
@RequestMapping("/batch/ens/sms/v1")
public class SmsMessageController {
private final ISmsMessageService service;
private final EnsBatchExtractService extractService;

@ -1,14 +1,21 @@
package kr.xit.core.aop;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.servlet.http.HttpServletRequest;
import kr.xit.core.biz.model.LoggingDTO;
import kr.xit.core.biz.service.ILoggingService;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.spring.util.error.ErrorParse;
import kr.xit.core.support.slack.SlackWebhookPush;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.JsonUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
@ -24,16 +31,6 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.biz.model.LoggingDTO;
import kr.xit.core.biz.service.ILoggingService;
import kr.xit.core.spring.util.error.ErrorParse;
import kr.xit.core.support.slack.SlackWebhookPush;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description : logging trace aspect
@ -74,8 +71,6 @@ public class TraceLoggerAspect {
private final ILoggingService loggingService;
private final SlackWebhookPush slackWebhookPush;
private static final String MESSAGE = "message";
private static final String CODE = "code";
private static final String REQUEST_TRACE_ID = "request_trace_id";
public TraceLoggerAspect(@Lazy ILoggingService loggingService, SlackWebhookPush slackWebhookPush) {
@ -95,9 +90,8 @@ public class TraceLoggerAspect {
traceLogging(JsonUtils.toJson(pjp.getArgs()), request);
Object result = pjp.proceed();
if(result instanceof CompletableFuture){
CompletableFuture future = (CompletableFuture)result;
//noinspection rawtypes
if(result instanceof CompletableFuture future){
while(true) {
if (future.isDone()) break;
}
@ -163,8 +157,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
protected void traceLoggingResult(final Object result) {
String success = "true";
//FIXME: slack webhook log push
if(result instanceof ApiResponseDTO<?>){
ApiResponseDTO<?> apiResponseDTO = (ApiResponseDTO<?>)result;
if(result instanceof ApiResponseDTO<?> apiResponseDTO){
if(!apiResponseDTO.isSuccess()){
success = "false";
@ -207,9 +200,9 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
}
private String getResult(final Object o){
if(o instanceof Future) {
//noinspection rawtypes
if(o instanceof Future future) {
try {
Future<?> future = (Future<?>)o;
return JsonUtils.toJson(future.get());
} catch (InterruptedException ie){
// thread pool에 에러 상태 전송
@ -256,4 +249,32 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
//if(RequestContextHolder.getRequestAttributes() != null)
MDC.clear();
}
@Getter
enum ApiSystemId {
KAKAO("KAKAO", "카카오", "/kakao/"),
KT_BC("KT-BC", "공공알림문자", "/kt/"),
PPLUS("POST-PLUS", "Post Plus", "/pplus/"),
NICE("NICE", "NICE CI", "/nice/"),
EPOST("EPOST", "E-POST", "/ag/"),
NONE("NONE", "미정의", "/미정의/"),
;
private final String code;
private final String desc;
private final String uri;
ApiSystemId(final String code, final String desc, final String uri) {
this.code = code;
this.desc = desc;
this.uri = uri;
}
public static ApiSystemId compareByUri(final String uri){
return Arrays.stream(ApiSystemId.values())
.filter(ssc -> uri.contains(ssc.getUri()))
.findFirst()
.orElseGet(() -> ApiSystemId.valueOf("NONE"));
}
}
}

Loading…
Cancel
Save