-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2.0
- Loading branch information
Showing
101 changed files
with
1,321 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/com/funeat/common/logging/Logging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.funeat.common.logging; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Logging { | ||
} |
91 changes: 91 additions & 0 deletions
91
backend/src/main/java/com/funeat/common/logging/LoggingAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.funeat.common.logging; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.AfterReturning; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.CodeSignature; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
@Aspect | ||
@Component | ||
public class LoggingAspect { | ||
|
||
private static final List<String> excludeNames = Arrays.asList("image", "images", "request"); | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Pointcut("execution(public * com.funeat.*.presentation.*.*(..))") | ||
private void allPresentation() { | ||
} | ||
|
||
@Pointcut("@annotation(com.funeat.common.logging.Logging)") | ||
private void logging() { | ||
} | ||
|
||
@Before("allPresentation() && logging()") | ||
public void requestLogging(final JoinPoint joinPoint) { | ||
final HttpServletRequest request = getRequest(); | ||
final Map<String, Object> args = getSpecificParameters(joinPoint); | ||
|
||
printRequestLog(request, args); | ||
} | ||
|
||
private HttpServletRequest getRequest() { | ||
final ServletRequestAttributes servletRequestAttributes | ||
= (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); | ||
return servletRequestAttributes.getRequest(); | ||
} | ||
|
||
private Map<String, Object> getSpecificParameters(final JoinPoint joinPoint) { | ||
final CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature(); | ||
final String[] parameterNames = codeSignature.getParameterNames(); | ||
final Object[] args = joinPoint.getArgs(); | ||
|
||
final Map<String, Object> params = new HashMap<>(); | ||
for (int i = 0; i < parameterNames.length; i++) { | ||
if (!excludeNames.contains(parameterNames[i])) { | ||
params.put(parameterNames[i], args[i]); | ||
} | ||
} | ||
|
||
return params; | ||
} | ||
|
||
private void printRequestLog(final HttpServletRequest request, final Object value) { | ||
try { | ||
log.info("[REQUEST {}] [PATH {}] {}", | ||
request.getMethod(), request.getRequestURI(), objectMapper.writeValueAsString(value)); | ||
} catch (final JsonProcessingException e) { | ||
log.warn("[LOGGING ERROR] Request 로깅에 실패했습니다"); | ||
} | ||
} | ||
|
||
@AfterReturning(value = "allPresentation() && logging()", returning = "responseEntity") | ||
public void requestLogging(final ResponseEntity<?> responseEntity) { | ||
printResponseLog(responseEntity); | ||
} | ||
|
||
private void printResponseLog(final ResponseEntity<?> responseEntity) { | ||
try { | ||
final String responseStatus = responseEntity.getStatusCode().toString(); | ||
log.info("[RESPONSE {}] {}", responseStatus, objectMapper.writeValueAsString(responseEntity.getBody())); | ||
} catch (final JsonProcessingException e) { | ||
log.warn("[LOGGING ERROR] Response 로깅에 실패했습니다"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
backend/src/main/java/com/funeat/member/dto/MemberRecipeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.