Skip to content

Commit 05181b5

Browse files
committed
refactor(notify): 운영 환경 로깅 개선
정상 동작은 debug, 중요 이벤트는 info로 로깅 개선
1 parent ef85a1b commit 05181b5

16 files changed

Lines changed: 40 additions & 77 deletions

src/main/java/com/devkor/ifive/nadab/domain/notification/application/NotificationCommandService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void sendNotification(
9090
notification.markAsNotificationDisabled();
9191
notificationRepository.save(notification);
9292

93-
log.info("Notification saved to inbox only (user disabled): userId={}, group={}, id={}, status=NOTIFICATION_DISABLED",
93+
log.debug("Notification saved to inbox only (user disabled): userId={}, group={}, id={}, status=NOTIFICATION_DISABLED",
9494
userId, group, notification.getId());
9595
return; // 이벤트 발행 안 함
9696
}
@@ -105,7 +105,7 @@ public void sendNotification(
105105
notification.markAsNotificationDisabled();
106106
notificationRepository.save(notification);
107107

108-
log.info("Notification saved to inbox only (no device): userId={}, id={}, status=NOTIFICATION_DISABLED",
108+
log.debug("Notification saved to inbox only (no device): userId={}, id={}, status=NOTIFICATION_DISABLED",
109109
userId, notification.getId());
110110
return; // 이벤트 발행 안 함
111111
}
@@ -116,7 +116,7 @@ public void sendNotification(
116116
);
117117
notificationRepository.save(notification);
118118

119-
log.info("Notification created (PENDING): id={}, type={}, userId={}",
119+
log.debug("Notification created (PENDING): id={}, type={}, userId={}",
120120
notification.getId(), type, userId);
121121

122122
// 6. 이벤트 발행 (트랜잭션 커밋 후 EventListener가 즉시 발송)

src/main/java/com/devkor/ifive/nadab/domain/notification/application/UserDeviceCommandService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public boolean registerDevice(
4848
|| !existing.getDeviceId().equals(deviceId)
4949
|| !existing.getPlatform().equals(platform)) {
5050
userDeviceRepository.delete(existing);
51-
log.info("Deleted existing token: was for userId={}, now for userId={}",
51+
log.debug("Deleted existing token: was for userId={}, now for userId={}",
5252
existing.getUser().getId(), userId);
5353
}
5454
}
@@ -61,14 +61,14 @@ public boolean registerDevice(
6161
// 기존 디바이스 토큰 업데이트
6262
UserDevice device = existingDevice.get();
6363
device.updateToken(fcmToken);
64-
log.info("Device token updated: userId={}, platform={}", userId, platform);
64+
log.debug("Device token updated: userId={}, platform={}", userId, platform);
6565
return false; // 기존 디바이스 업데이트
6666
} else {
6767
// 새 디바이스 등록
6868
try {
6969
UserDevice newDevice = UserDevice.create(user, fcmToken, deviceId, platform);
7070
userDeviceRepository.save(newDevice);
71-
log.info("Device registered: userId={}, platform={}", userId, platform);
71+
log.debug("Device registered: userId={}, platform={}", userId, platform);
7272
return true; // 새 디바이스 등록
7373
} catch (DataIntegrityViolationException e) {
7474
// 동시성으로 인해 이미 생성된 경우 (Race Condition)
@@ -114,6 +114,6 @@ public void deleteDevice(Long userId, String deviceId, DevicePlatform platform)
114114
.orElseThrow(() -> new NotFoundException(ErrorCode.DEVICE_NOT_FOUND));
115115

116116
userDeviceRepository.delete(device);
117-
log.info("Device deleted: userId={}, deviceId={}, platform={}", userId, deviceId, platform);
117+
log.debug("Device deleted: userId={}, deviceId={}, platform={}", userId, deviceId, platform);
118118
}
119119
}

src/main/java/com/devkor/ifive/nadab/domain/notification/application/event/NotificationEventListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class NotificationEventListener {
4949
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
5050
public void handleNotificationCreated(NotificationCreatedEvent event) {
5151
Long notificationId = event.getNotificationId();
52-
log.debug("Handling notification created event: id={}", notificationId);
5352

5453
try {
5554
// T2: PENDING → SENDING & fcmSent = true (낙관적 설정)

src/main/java/com/devkor/ifive/nadab/domain/notification/application/event/friend/FriendNotificationEventListener.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public class FriendNotificationEventListener {
3838
@Async("notificationTaskExecutor")
3939
@EventListener
4040
public void handleFriendRequestReceived(FriendRequestReceivedEvent event) {
41-
log.debug("Handling friend request received event: friendshipId={}, receiverId={}, requesterId={}",
42-
event.getFriendshipId(), event.getReceiverId(), event.getRequesterId());
43-
4441
try {
4542
// 요청자 정보 조회
4643
User requester = userRepository.findById(event.getRequesterId())
@@ -71,7 +68,7 @@ public void handleFriendRequestReceived(FriendRequestReceivedEvent event) {
7168
idempotencyKey
7269
);
7370

74-
log.info("Friend request notification created: friendshipId={}, receiverId={}",
71+
log.debug("Friend request notification created: friendshipId={}, receiverId={}",
7572
event.getFriendshipId(), event.getReceiverId());
7673

7774
} catch (Exception e) {
@@ -87,9 +84,6 @@ public void handleFriendRequestReceived(FriendRequestReceivedEvent event) {
8784
@Async("notificationTaskExecutor")
8885
@EventListener
8986
public void handleFriendRequestAccepted(FriendRequestAcceptedEvent event) {
90-
log.debug("Handling friend request accepted event: friendshipId={}, requesterId={}, accepterId={}",
91-
event.getFriendshipId(), event.getRequesterId(), event.getAccepterId());
92-
9387
try {
9488
// 수락자 정보 조회
9589
User accepter = userRepository.findById(event.getAccepterId())
@@ -120,7 +114,7 @@ public void handleFriendRequestAccepted(FriendRequestAcceptedEvent event) {
120114
idempotencyKey
121115
);
122116

123-
log.info("Friend accepted notification created: friendshipId={}, requesterId={}",
117+
log.debug("Friend accepted notification created: friendshipId={}, requesterId={}",
124118
event.getFriendshipId(), event.getRequesterId());
125119

126120
} catch (Exception e) {

src/main/java/com/devkor/ifive/nadab/domain/notification/application/event/report/ReportNotificationEventListener.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public class ReportNotificationEventListener {
5353
@Async("notificationTaskExecutor")
5454
@EventListener
5555
public void handleWeeklyReportCompleted(WeeklyReportCompletedEvent event) {
56-
log.debug("Handling weekly report completed event: reportId={}, userId={}",
57-
event.getReportId(), event.getUserId());
58-
5956
try {
6057
// 메시지 생성
6158
NotificationContent content = messageFactory.createMessage(
@@ -75,7 +72,7 @@ public void handleWeeklyReportCompleted(WeeklyReportCompletedEvent event) {
7572
idempotencyKey
7673
);
7774

78-
log.info("Weekly report completed notification created: reportId={}, userId={}",
75+
log.debug("Weekly report completed notification created: reportId={}, userId={}",
7976
event.getReportId(), event.getUserId());
8077

8178
} catch (Exception e) {
@@ -90,9 +87,6 @@ public void handleWeeklyReportCompleted(WeeklyReportCompletedEvent event) {
9087
@Async("notificationTaskExecutor")
9188
@EventListener
9289
public void handleMonthlyReportCompleted(MonthlyReportCompletedEvent event) {
93-
log.debug("Handling monthly report completed event: reportId={}, userId={}",
94-
event.getReportId(), event.getUserId());
95-
9690
try {
9791
// 메시지 생성
9892
NotificationContent content = messageFactory.createMessage(
@@ -112,7 +106,7 @@ public void handleMonthlyReportCompleted(MonthlyReportCompletedEvent event) {
112106
idempotencyKey
113107
);
114108

115-
log.info("Monthly report completed notification created: reportId={}, userId={}",
109+
log.debug("Monthly report completed notification created: reportId={}, userId={}",
116110
event.getReportId(), event.getUserId());
117111

118112
} catch (Exception e) {
@@ -127,9 +121,6 @@ public void handleMonthlyReportCompleted(MonthlyReportCompletedEvent event) {
127121
@Async("notificationTaskExecutor")
128122
@EventListener
129123
public void handleTypeReportCompleted(TypeReportCompletedEvent event) {
130-
log.debug("Handling type report completed event: reportId={}, userId={}, categoryName={}",
131-
event.getReportId(), event.getUserId(), event.getCategoryName());
132-
133124
try {
134125
// 메시지 생성
135126
Map<String, String> params = Map.of("categoryName", event.getCategoryName());
@@ -150,7 +141,7 @@ public void handleTypeReportCompleted(TypeReportCompletedEvent event) {
150141
idempotencyKey
151142
);
152143

153-
log.info("Type report completed notification created: reportId={}, userId={}, categoryName={}",
144+
log.debug("Type report completed notification created: reportId={}, userId={}, categoryName={}",
154145
event.getReportId(), event.getUserId(), event.getCategoryName());
155146

156147
} catch (Exception e) {
@@ -167,8 +158,6 @@ public void handleTypeReportCompleted(TypeReportCompletedEvent event) {
167158
@Async("notificationTaskExecutor")
168159
@EventListener
169160
public void handleWeeklyReportAvailable(WeeklyReportAvailableEvent event) {
170-
log.debug("Handling weekly report available event: userId={}", event.getUserId());
171-
172161
try {
173162
// 메시지 생성
174163
NotificationContent content = messageFactory.createMessage(
@@ -189,7 +178,7 @@ public void handleWeeklyReportAvailable(WeeklyReportAvailableEvent event) {
189178
idempotencyKey
190179
);
191180

192-
log.info("Weekly report available notification created: userId={}", event.getUserId());
181+
log.debug("Weekly report available notification created: userId={}", event.getUserId());
193182

194183
} catch (Exception e) {
195184
log.error("Failed to handle weekly report available event: userId={}, error={}",
@@ -203,9 +192,6 @@ public void handleWeeklyReportAvailable(WeeklyReportAvailableEvent event) {
203192
@Async("notificationTaskExecutor")
204193
@EventListener
205194
public void handleMonthlyReportAvailable(MonthlyReportAvailableEvent event) {
206-
log.debug("Handling monthly report available event: userId={}, nickname={}",
207-
event.getUserId(), event.getNickname());
208-
209195
try {
210196
// 메시지 생성
211197
Map<String, String> params = Map.of("nickname", event.getNickname());
@@ -227,7 +213,7 @@ public void handleMonthlyReportAvailable(MonthlyReportAvailableEvent event) {
227213
idempotencyKey
228214
);
229215

230-
log.info("Monthly report available notification created: userId={}", event.getUserId());
216+
log.debug("Monthly report available notification created: userId={}", event.getUserId());
231217

232218
} catch (Exception e) {
233219
log.error("Failed to handle monthly report available event: userId={}, error={}",
@@ -242,9 +228,6 @@ public void handleMonthlyReportAvailable(MonthlyReportAvailableEvent event) {
242228
@Async("notificationTaskExecutor")
243229
@EventListener
244230
public void handleDailyReportCompleted(DailyReportCompletedEvent event) {
245-
log.debug("Handling daily report completed event: userId={}, interestCode={}",
246-
event.getUserId(), event.getInterestCode());
247-
248231
try {
249232
// 해당 InterestCode의 총 답변 개수 조회
250233
long answerCount = answerEntryRepository.countByUserIdAndInterestCode(
@@ -319,7 +302,7 @@ private void sendTypeReportAvailableNotification(Long userId, InterestCode inter
319302
idempotencyKey
320303
);
321304

322-
log.info("Type report available notification created: userId={}, interestCode={}, milestone={}",
305+
log.debug("Type report available notification created: userId={}, interestCode={}, milestone={}",
323306
userId, interestCode, milestone);
324307
}
325308

src/main/java/com/devkor/ifive/nadab/domain/notification/application/helper/NotificationTransactionHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public boolean updateFinalStatus(Long notificationId, boolean fcmSuccess) {
8080
);
8181

8282
if (updated == 1) {
83-
log.info("✅ Notification sent successfully: id={}", notificationId);
83+
log.debug("✅ Notification sent successfully: id={}", notificationId);
8484
return true;
8585
} else {
8686
log.warn("Status already changed during send: id={}, will be recovered by RecoveryScheduler",
@@ -146,7 +146,7 @@ public boolean markAsSentIfFcmSent(Long notificationId) {
146146
int updated = notificationRepository.markAsSentIfFcmSent(notificationId);
147147

148148
if (updated == 1) {
149-
log.info("✅ FCM already sent, marked as SENT: id={}", notificationId);
149+
log.debug("✅ FCM already sent, marked as SENT: id={}", notificationId);
150150
return true;
151151
}
152152

src/main/java/com/devkor/ifive/nadab/domain/notification/application/scheduler/NotificationRecoveryScheduler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void recoverStuckNotifications() {
5252
return;
5353
}
5454

55-
log.warn("Recovering {} stuck SENDING notifications (timeout: {} minutes)",
55+
log.debug("Recovering {} stuck SENDING notifications (timeout: {} minutes)",
5656
stuckList.size(), TIMEOUT_MINUTES);
5757

5858
int recoveredToSent = 0;
@@ -70,7 +70,7 @@ public void recoverStuckNotifications() {
7070
}
7171
}
7272

73-
log.info("Recovery completed: SENT={}, PENDING={}, DEAD_LETTER={}, alreadyProcessed={}",
73+
log.debug("Recovery completed: SENT={}, PENDING={}, DEAD_LETTER={}, alreadyProcessed={}",
7474
recoveredToSent, recoveredToPending, recoveredToDeadLetter, alreadyProcessed);
7575

7676
} catch (Exception e) {

src/main/java/com/devkor/ifive/nadab/domain/notification/application/scheduler/NotificationRetryScheduler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void retryPendingNotifications() {
7676
return;
7777
}
7878

79-
log.info("Retrying {} PENDING notifications (EventListener Fallback)", pendingList.size());
79+
log.debug("Retrying {} PENDING notifications (EventListener Fallback)", pendingList.size());
8080

8181
// 배치 처리
8282
processBatch(pendingList, NotificationStatus.PENDING);
@@ -102,7 +102,7 @@ private void retryFailedNotifications() {
102102
transactionHelper.moveFailedToDeadLetter();
103103

104104
if (totalRetried > 0) {
105-
log.info("Retried {} FAILED notifications with Exponential Backoff", totalRetried);
105+
log.debug("Retried {} FAILED notifications with Exponential Backoff", totalRetried);
106106
}
107107
}
108108

@@ -127,7 +127,7 @@ protected int retryFailedByRetryCount(int retryCount, OffsetDateTime now) {
127127
return 0;
128128
}
129129

130-
log.info("Retrying {} FAILED notifications: retryCount={}, delay={}s",
130+
log.debug("Retrying {} FAILED notifications: retryCount={}, delay={}s",
131131
failedList.size(), retryCount, delaySeconds);
132132

133133
// FAILED → 바로 재발송
@@ -150,7 +150,7 @@ protected void processBatch(List<Notification> notifications, NotificationStatus
150150
return;
151151
}
152152

153-
log.info("Acquired {} notifications for batch processing", acquiredList.size());
153+
log.debug("Acquired {} notifications for batch processing", acquiredList.size());
154154

155155
try {
156156
// FCM 발송 (트랜잭션 밖)
@@ -221,7 +221,7 @@ protected void updateBatchResults(List<Notification> notifications, Map<Long, Bo
221221
int actualRetryCount = (fromStatus == NotificationStatus.FAILED)
222222
? notification.getRetryCount() + 1
223223
: notification.getRetryCount();
224-
log.info("✅ Notification sent successfully: id={}, retryCount={}",
224+
log.debug("✅ Notification sent successfully: id={}, retryCount={}",
225225
notificationId, actualRetryCount);
226226
}
227227
} else {

src/main/java/com/devkor/ifive/nadab/domain/notification/application/scheduler/answer/DailyWriteReminderScheduler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public void sendDailyWriteReminder() {
6262
List<User> targetUsers = notificationSettingRepository.findUsersForDailyWriteReminder(currentTime);
6363

6464
if (targetUsers.isEmpty()) {
65-
log.trace("No users to notify at {}", currentTime);
65+
log.debug("No users to notify at {}", currentTime);
6666
return;
6767
}
6868

69-
log.info("Found {} users for daily write reminder at {}", targetUsers.size(), currentTime);
69+
log.debug("Found {} users for daily write reminder at {}", targetUsers.size(), currentTime);
7070

7171
// 2. 오늘 이미 답변한 사용자 제외
7272
List<Long> targetUserIds = targetUsers.stream()
@@ -83,11 +83,11 @@ public void sendDailyWriteReminder() {
8383
.toList();
8484

8585
if (usersToNotify.isEmpty()) {
86-
log.info("All users already answered today, skip notification");
86+
log.debug("All users already answered today, skip notification");
8787
return;
8888
}
8989

90-
log.info("Users to notify after filtering: {} (answered: {})",
90+
log.debug("Users to notify after filtering: {} (answered: {})",
9191
usersToNotify.size(), answeredUserIds.size());
9292

9393
// 3. FCM 토큰 조회

src/main/java/com/devkor/ifive/nadab/domain/notification/application/scheduler/answer/InactiveUserNotificationScheduler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class InactiveUserNotificationScheduler {
5858
*/
5959
@Scheduled(cron = "0 0 22 * * *", zone = "Asia/Seoul")
6060
public void notifyInactiveUsers() {
61-
log.info("Starting inactive user notification scheduler");
61+
log.debug("Starting inactive user notification scheduler");
6262

6363
try {
6464
// 날짜 변경 시 중복 방지 Set 초기화
@@ -72,7 +72,7 @@ public void notifyInactiveUsers() {
7272
List<UserWithLastAnswerDate> results = answerEntryRepository.findUsersWithLastAnswerBefore(cutoffDate);
7373

7474
if (results.isEmpty()) {
75-
log.info("No inactive users found");
75+
log.debug("No inactive users found");
7676
return;
7777
}
7878

@@ -141,7 +141,7 @@ private boolean sendInactiveUserNotification(
141141
try {
142142
// 1. 알림 설정 체크
143143
if (setting != null && !setting.isEnabled()) {
144-
log.info("User disabled notification group, skip: userId={}, group={}",
144+
log.debug("User disabled notification group, skip: userId={}, group={}",
145145
user.getId(), setting.getGroup());
146146
return false;
147147
}
@@ -159,7 +159,7 @@ private boolean sendInactiveUserNotification(
159159

160160
// 3. FCM 토큰 검증
161161
if (devices.isEmpty()) {
162-
log.info("No FCM tokens found, skip: userId={}", user.getId());
162+
log.debug("No FCM tokens found, skip: userId={}", user.getId());
163163
return false;
164164
}
165165

@@ -169,7 +169,7 @@ private boolean sendInactiveUserNotification(
169169
.toList();
170170

171171
if (tokens.isEmpty()) {
172-
log.info("No valid FCM tokens, skip: userId={}", user.getId());
172+
log.debug("No valid FCM tokens, skip: userId={}", user.getId());
173173
return false;
174174
}
175175

@@ -188,7 +188,7 @@ private boolean sendInactiveUserNotification(
188188

189189
fcmClient.sendMulticast(tokens, messageDto);
190190

191-
log.info("Inactive user push notification sent: userId={}, daysInactive={}, deviceCount={}",
191+
log.debug("Inactive user push notification sent: userId={}, daysInactive={}, deviceCount={}",
192192
user.getId(), daysInactive, tokens.size());
193193

194194
return true;

0 commit comments

Comments
 (0)