forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/be/#230 Global Logging 추가 + Backend README 일부 작성
- Loading branch information
Showing
157 changed files
with
9,926 additions
and
1,998 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 |
---|---|---|
|
@@ -4,7 +4,6 @@ on: | |
push: | ||
branches: | ||
- develop-back | ||
- main | ||
permissions: | ||
contents: read | ||
|
||
|
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
62 changes: 62 additions & 0 deletions
62
back-gateway/src/main/java/com/gateway/backgateway/filter/GlobalLoggingFilter.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,62 @@ | ||
package com.gateway.backgateway.filter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cloud.gateway.filter.GlobalFilter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.io.buffer.DataBuffer; | ||
import org.springframework.core.io.buffer.DataBufferUtils; | ||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class GlobalLoggingFilter { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Bean | ||
@Order(-1) | ||
public GlobalFilter preLoggingFilter() { | ||
return (exchange, chain) -> { | ||
ServerHttpRequest request = exchange.getRequest(); | ||
return DataBufferUtils.join(request.getBody()) | ||
.flatMap(dataBuffer -> { | ||
byte[] bodyBytes = new byte[dataBuffer.readableByteCount()]; | ||
dataBuffer.read(bodyBytes); | ||
DataBufferUtils.release(dataBuffer); | ||
String bodyString = new String(bodyBytes, StandardCharsets.UTF_8); | ||
String jsonBody; | ||
try { | ||
Object json = objectMapper.readValue(bodyString, Object.class); | ||
jsonBody = objectMapper.writeValueAsString(json); | ||
} catch (Exception e) { | ||
jsonBody = bodyString; | ||
} | ||
|
||
log.info("Global Filter Start: request id -> {}", request.getId()); | ||
log.info("Request: {} {}", request.getMethod(), request.getURI()); | ||
log.info("Request Body: {}", jsonBody); | ||
|
||
return chain.filter(exchange); | ||
}); | ||
}; | ||
} | ||
|
||
@Bean | ||
@Order(Ordered.LOWEST_PRECEDENCE) | ||
public GlobalFilter postLoggingFilter() { | ||
return (exchange, chain) -> { | ||
return chain.filter(exchange).then(Mono.fromRunnable(() -> { | ||
log.info("Response: " + exchange.getResponse().getStatusCode()); | ||
})); | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,41 @@ | ||
# JWT Secret Key | ||
JWT_SECRET= | ||
JWT_ACCESS_EXPIRATION_TIME= | ||
JWT_REFRESH_EXPIRATION_TIME= | ||
|
||
# HMAC | ||
HMAC_SECRET= | ||
HMAC_ALGORITHM= | ||
HMAC_ALGORITHM= | ||
|
||
#DeepL | ||
DeepL_API_KEY= | ||
|
||
#MYSQL | ||
DB_ENDPOINT= | ||
DB_PORT= | ||
DB_NAME= | ||
MYSQL_USERNAME= | ||
MYSQL_PASSWORD= | ||
|
||
#TEST | ||
TEST_KEY= | ||
|
||
#Azure | ||
Azure_API_KEY= | ||
|
||
##REDIS | ||
REDIS_HOST= | ||
REDIS_PORT= | ||
|
||
## S3 | ||
S3_ACCESS_KEY= | ||
S3_SECRET_KEY= | ||
|
||
## Ruby On Rails Production Key | ||
SECRET_KEY_BASE= | ||
|
||
## Nginx ENV | ||
SERVER_NAME= | ||
|
||
## CHAT BOT ENV | ||
CHATBOT_URL= |
Oops, something went wrong.