티스토리 뷰
반응형
Spring boot AOP 로깅
@Slf4j
@Aspect
@Component
public class LogAspect {
@Autowired
private JwtUtils jwtUtils;
@Around("execution( * com.xxx.api.domain..controller..*(..)) && args(.., @RequestBody requestBody)")
public Object logging(ProceedingJoinPoint pjp, Object requestBody) {
Object result = null;
try {
long startAt = System.currentTimeMillis();
result = pjp.proceed();
long endAt = System.currentTimeMillis();
log.info("### API-CALL : {} ({}ms) ", getRequestData(pjp, requestBody), (endAt-startAt));
} catch (Throwable e) {
log.info(e.getMessage());
throw new CommonRuntimeException(ResponseCode.LOGGING_ERROR);
}
return result;
}
private String getRequestData(ProceedingJoinPoint pjp, Object requestBody) {
Map<String, Object> dataMap = new LinkedHashMap<>();
RequestAttributes requestAttribute = RequestContextHolder.getRequestAttributes();
if(requestAttribute != null){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
dataMap.put("uri", request.getRequestURI());
dataMap.put("method", request.getMethod());
dataMap.put("controller", pjp.getSignature().getDeclaringType().getSimpleName());
dataMap.put("access_token", jwtUtils.getAccessToken());
// dataMap.put("param", this.paramToMap(request.getParameterMap()));
dataMap.put("body", this.requestBodyToMap(requestBody));
}
return mapToJson(dataMap);
}
private Map<String, Object> paramToMap(Map<String, String[]> paramMap) {
Map<String, Object> dataMap = new LinkedHashMap<>();
paramMap.forEach((key, value) -> {
String values = String.join("", value);
dataMap.put(key, values);
});
return dataMap;
}
private Map<String, Object> requestBodyToMap(Object requestBody) {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> dataMap = objectMapper.registerModule(new JavaTimeModule()).convertValue(requestBody, Map.class);
return dataMap;
}
private String mapToJson(Map<String, Object> dataMap){
String data = null;
try {
ObjectMapper objectMapper = new ObjectMapper();
data = objectMapper.writeValueAsString(dataMap);
} catch (JsonProcessingException e) {
log.error("mapToJson ::: Redis Object Set Error");
}
return data;
}
}
끗!@#$!@#$!
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 돌장갑
- 담양 여행
- 나래바이크
- 스쿠터 여행
- 리니지m
- 은파호수공원
- 영광 여행
- 송내역 룸카페
- 군산 여행
- 송내 카페
- 송내 룸카페
- 제주도 스쿠터 여행
- 군산 가볼만한곳
- 베스파LX
- 송내역 카페
- 보성 여행
- 국제반점
- 고흥 여행
- 군산 게스트하우스
- 인터바이크
- 남자 혼자 국내 여행
- kendo grid
- 남자 혼자 여행
- Docker
- 윈드스크린
- 전국 일주 여행
- 스쿠터 전국 일주
- vscode
- 오라클 DB 링크
- 초원사진관
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함