Skip to content

Commit

Permalink
feat : logback 수정 (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
Choon0414 authored Sep 14, 2024
1 parent 9a88850 commit 012417a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

implementation 'net.logstash.logback:logstash-logback-encoder:8.0'

implementation 'io.jsonwebtoken:jjwt-api:0.12.3'

implementation 'org.jsoup:jsoup:1.15.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ public class ErrorResponse {
private final int status;
private final String message;
private final String code;
private final String errorTraceId;

public ErrorResponse(int status, String message) {
public ErrorResponse(int status, String message, String errorTraceId) {
this.status = status;
this.message = message;
this.code = "";
this.errorTraceId = errorTraceId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.catalina.connector.ClientAbortException;
Expand Down Expand Up @@ -230,7 +231,9 @@ private ResponseEntity<Object> buildErrorResponse(
HttpStatus httpStatus,
String message
) {
var response = new ErrorResponse(httpStatus.value(), message);
String errorTraceId = UUID.randomUUID().toString();
log.warn("traceId: {}", errorTraceId);
var response = new ErrorResponse(httpStatus.value(), message, errorTraceId);
return ResponseEntity.status(httpStatus).body(response);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@
<level>ERROR</level>
</filter>
</appender>

<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="FILE"/>
</root>
</springProfile>
</configuration>

0 comments on commit 012417a

Please sign in to comment.