-
Notifications
You must be signed in to change notification settings - Fork 2
prod : DiscordNotifier 에러 내용 전달 시, TimeStamp 를 포함하도록 구성 #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 12 additions & 4 deletions
16
...ava/life/mosu/mosuserver/infra/notify/dto/discord/DiscordExceptionNotifyEventRequest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,30 +1,38 @@ | ||
| package life.mosu.mosuserver.infra.notify.dto.discord; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| public record DiscordExceptionNotifyEventRequest( | ||
| String exceptionCause, | ||
| String exceptionMessage, | ||
| String meta | ||
| String meta, | ||
| LocalDateTime timestamp | ||
| ) { | ||
|
|
||
| public static DiscordExceptionNotifyEventRequest of( | ||
| String exceptionCause, | ||
| String exceptionMessage, | ||
| String meta | ||
| ) { | ||
| return new DiscordExceptionNotifyEventRequest(exceptionCause, exceptionMessage, meta); | ||
| return new DiscordExceptionNotifyEventRequest(exceptionCause, exceptionMessage, meta, | ||
| LocalDateTime.now()); | ||
| } | ||
|
|
||
| public static DiscordExceptionNotifyEventRequest of( | ||
| String exceptionCause, | ||
| String exceptionMessage | ||
| ) { | ||
| return new DiscordExceptionNotifyEventRequest(exceptionCause, exceptionMessage, null); | ||
| return new DiscordExceptionNotifyEventRequest(exceptionCause, exceptionMessage, null, | ||
| LocalDateTime.now()); | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return "⚠️ **알림 전송**\n" | ||
| + String.format("- ⚠️ exception Cause : `%s`\n", exceptionCause) | ||
| + String.format("- 📨 exception Message: `%s`\n", exceptionMessage) | ||
| + String.format("- 📋 meta: `%s`", meta == null ? "없음" : meta); | ||
| + String.format("- 📋 meta: `%s`\n", meta == null ? "없음" : meta) | ||
| + String.format("- ⏰ timestamp: `%s`", timestamp.format( | ||
| DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be improved for both performance and readability.
Performance:
DateTimeFormatter.ofPattern(...)creates a new formatter instance on every call, which is inefficient. SinceDateTimeFormatteris thread-safe, it's best to define it as aprivate static finalconstant in the record and reuse it.Readability: The string construction using
+and multipleString.formatcalls can be simplified. Using a text block (available since Java 15) with the.formatted()method would make the code much cleaner.Here is an example of how you could refactor this: