Skip to content

Commit fa15223

Browse files
authored
[Release] V2.1.2 로그 관련 기능 수정
[Release] V2.1.2 로그 관련 기능 수정
2 parents 773d103 + 3ec24be commit fa15223

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/main/java/ssu/eatssu/domain/restaurant/entity/Restaurant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Getter
1111
public enum Restaurant {
1212

13-
DODAM("DODAM", 7000),
13+
DODAM("DODAM", 6000),
1414
DORMITORY("DORMITORY", 5500),
1515
FOOD_COURT("FOOD_COURT", null),
1616
SNACK_CORNER("SNACK_CORNER", null),

src/main/java/ssu/eatssu/domain/slack/entity/SlackMessageFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static String sendServerError(Throwable ex, String method, String uri, St
8484
- HTTP Method: {4}
8585
- URI: {5}
8686
- User ID: {6}
87-
- 요청 파라미터: {7}
87+
- 로그 내용 (파라미터 정보 포함): {7}
8888
===================
8989
""";
9090
MessageFormat messageFormat = new MessageFormat(messageTemplate);

src/main/java/ssu/eatssu/global/log/ControllerLogAspect.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.aspectj.lang.annotation.Aspect;
1010
import org.aspectj.lang.annotation.Pointcut;
1111
import org.aspectj.lang.reflect.MethodSignature;
12+
import org.springframework.security.core.Authentication;
13+
import org.springframework.security.core.context.SecurityContextHolder;
1214
import org.springframework.security.core.userdetails.UserDetails;
1315
import org.springframework.stereotype.Component;
1416
import org.springframework.web.context.request.RequestContextHolder;
@@ -51,15 +53,7 @@ public Object logApi(ProceedingJoinPoint joinPoint) throws Throwable {
5153
String[] paramNames = methodSignature.getParameterNames();
5254
Object[] args = joinPoint.getArgs();
5355

54-
// 요청자
55-
String userId = IntStream.range(0, args.length)
56-
.filter(i -> args[i] instanceof CustomUserDetails)
57-
.mapToObj(i -> {
58-
CustomUserDetails user = (CustomUserDetails) args[i];
59-
return String.valueOf(user.getId());
60-
})
61-
.findFirst()
62-
.orElse("anonymous");
56+
String userId = getUserIdFromSecurityContext();
6357

6458
String userIdLog = "userId=" + userId;
6559

@@ -127,6 +121,15 @@ private String getCauseMessage(Throwable e) {
127121
return message != null ? message : e.getClass().getSimpleName();
128122
}
129123

124+
private String getUserIdFromSecurityContext() {
125+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
126+
if (authentication != null && authentication.isAuthenticated() && authentication.getPrincipal() instanceof CustomUserDetails) {
127+
CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();
128+
return String.valueOf(userDetails.getId());
129+
}
130+
return "anonymous";
131+
}
132+
130133
private Map<String, Object> toSafeMap(Object arg) {
131134
Map<String, Object> result = new HashMap<>();
132135
for (Field field : arg.getClass().getDeclaredFields()) {

0 commit comments

Comments
 (0)