-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from woowacourse-teams/develop-backend
백엔드 변경사항을 Develop 브랜치에 반영
- Loading branch information
Showing
8 changed files
with
114 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/backend/out | ||
/frontend/.idea | ||
/backend/htmlReport | ||
*.pem |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ build/ | |
out | ||
logs | ||
src/main/resources/firebase | ||
src/main/resources/application-prod.yml |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/mouda/backend/aop/logging/ExceptRequestLogging.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,12 @@ | ||
package mouda.backend.aop.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 ExceptRequestLogging { | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
backend/src/main/java/mouda/backend/aop/logging/RequestLoggingAspect.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,96 @@ | ||
package mouda.backend.aop.logging; | ||
|
||
import static java.util.stream.Collectors.*; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
|
||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import mouda.backend.darakbangmember.domain.DarakbangMember; | ||
import mouda.backend.member.domain.Member; | ||
|
||
@Aspect | ||
@Component | ||
@Slf4j | ||
public class RequestLoggingAspect { | ||
|
||
@Pointcut("execution(* mouda.backend..controller.*Controller.*(..))") | ||
public void allController() { | ||
} | ||
|
||
@Before("allController()") | ||
public void logController(JoinPoint joinPoint) { | ||
HttpServletRequest request = getHttpServletRequest(); | ||
|
||
MethodSignature signature = (MethodSignature)joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
if (method.isAnnotationPresent(ExceptRequestLogging.class)) { | ||
return; | ||
} | ||
|
||
String uri = request.getRequestURI(); | ||
String httpMethod = request.getMethod(); | ||
String queryParameters = getQueryParameters(request); | ||
String body = getBody(joinPoint); | ||
|
||
String memberInfo = getMemberInfo(joinPoint); | ||
|
||
log.info("Request Logging: {} {} member - {} body - {} parameters - {}", httpMethod, uri, memberInfo, body, | ||
queryParameters); | ||
} | ||
|
||
private String getMemberInfo(JoinPoint joinPoint) { | ||
for (Object arg : joinPoint.getArgs()) { | ||
if (arg instanceof Member) { | ||
return "Member ID: " + ((Member)arg).getId(); | ||
} | ||
if (arg instanceof DarakbangMember) { | ||
return "DarakbangMember ID: " + ((DarakbangMember)arg).getId(); | ||
} | ||
} | ||
return "No member"; | ||
} | ||
|
||
private HttpServletRequest getHttpServletRequest() { | ||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes(); | ||
return requestAttributes.getRequest(); | ||
} | ||
|
||
private String getQueryParameters(HttpServletRequest request) { | ||
String queryParameters = request.getParameterMap() | ||
.entrySet() | ||
.stream() | ||
.map(entry -> "%s = %s".formatted(entry.getKey(), entry.getValue()[0])) | ||
.collect(joining(", ")); | ||
|
||
if (queryParameters.isEmpty()) { | ||
return null; | ||
} | ||
return queryParameters; | ||
} | ||
|
||
private String getBody(JoinPoint joinPoint) { | ||
MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature(); | ||
Parameter[] parameters = methodSignature.getMethod().getParameters(); | ||
Object[] args = joinPoint.getArgs(); | ||
for (int i = 0; i < parameters.length; i++) { | ||
Parameter param = parameters[i]; | ||
Object arg = args[i]; | ||
if (param.isAnnotationPresent(RequestBody.class)) { | ||
return arg.toString(); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
26 changes: 0 additions & 26 deletions
26
backend/src/main/java/mouda/backend/config/interceptor/ApiRequestLoggingInterceptor.java
This file was deleted.
Oops, something went wrong.