Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
APP_AUDIT_LOG_PATH: ${APP_AUDIT_LOG_PATH:-/var/log/spring-boot/audit}
ports:
- "${APP_PORT:-8080}:8080"
- "127.0.0.1:${API_METRICS_HOST_PORT:-19090}:9090"
volumes:
- spring-boot-logs:/var/log/spring-boot
depends_on:
Expand Down Expand Up @@ -70,6 +71,8 @@ services:
condition: service_started
rabbitmq:
condition: service_healthy
ports:
- "127.0.0.1:${WORKER_METRICS_HOST_PORT:-18000}:8000"
restart: unless-stopped

loki:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ private PaymentLogMasking() {

public static Map<String, String> paymentContext(
String orderId,
String paymentKey,
Long userId,
String planCode,
Integer amount
Expand All @@ -19,10 +18,6 @@ public static Map<String, String> paymentContext(
if (orderId != null) {
context.put("orderId", orderId);
}
String maskedPaymentKey = maskPaymentKey(paymentKey);
if (maskedPaymentKey != null) {
context.put("paymentKey", maskedPaymentKey);
}
if (userId != null) {
context.put("paymentUserId", String.valueOf(userId));
}
Expand All @@ -35,17 +30,7 @@ public static Map<String, String> paymentContext(
return context;
}

public static Map<String, String> paymentContext(String orderId, String paymentKey, Integer amount) {
return paymentContext(orderId, paymentKey, null, null, amount);
}

public static String maskPaymentKey(String paymentKey) {
if (paymentKey == null || paymentKey.isBlank()) {
return null;
}
if (paymentKey.length() <= 10) {
return "****";
}
return paymentKey.substring(0, 6) + "..." + paymentKey.substring(paymentKey.length() - 4);
public static Map<String, String> paymentContext(String orderId, Integer amount) {
return paymentContext(orderId, null, null, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public PaymentPrepareResponse prepare(User user, PaymentPrepareRequest request)
try (var ignored = LoggingContext.with(
"payment.prepare.started",
null,
PaymentLogMasking.paymentContext(null, null, validatedUser.getId(), request.planCode(), plan.getPrice())
PaymentLogMasking.paymentContext(null, validatedUser.getId(), request.planCode(), plan.getPrice())
)) {
log.info("Starting payment preparation");
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public PaymentPrepareResponse prepare(User user, PaymentPrepareRequest request)
try (var ignored = LoggingContext.with(
"payment.create.completed",
null,
PaymentLogMasking.paymentContext(payment.getOrderId(), null, validatedUser.getId(), plan.getCode(), plan.getPrice())
PaymentLogMasking.paymentContext(payment.getOrderId(), validatedUser.getId(), plan.getCode(), plan.getPrice())
)) {
log.info("Payment preparation completed");
}
Expand Down Expand Up @@ -175,7 +175,7 @@ private PaymentPrepareResponse preparePortOne(User validatedUser, CreditPlan pla
try (var ignored = LoggingContext.with(
"payment.portone.prepare.completed",
null,
PaymentLogMasking.paymentContext(payment.getOrderId(), null, validatedUser.getId(), plan.getCode(), plan.getPrice())
PaymentLogMasking.paymentContext(payment.getOrderId(), validatedUser.getId(), plan.getCode(), plan.getPrice())
)) {
log.info("PortOne payment preparation completed");
}
Expand All @@ -197,7 +197,6 @@ public PaymentConfirmResponse confirm(User user, PaymentConfirmRequest request)
User validatedUser = userService.validateUser(user);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(
request.orderId(),
request.paymentKey(),
validatedUser.getId(),
null,
request.amount()
Expand Down Expand Up @@ -329,7 +328,7 @@ public void handlePortOneWebhook(String rawBody, HttpHeaders headers) {
try (var ignored = LoggingContext.with(
"payment.portone.webhook.ignored",
e.getCode(),
PaymentLogMasking.paymentContext(payload.data().paymentId(), null, null)
PaymentLogMasking.paymentContext(payload.data().paymentId(), null)
)) {
log.warn("PortOne webhook ignored: {}", e.getMessage());
}
Expand All @@ -343,7 +342,6 @@ public void handlePortOneWebhook(String rawBody, HttpHeaders headers) {
public void handleTossPayCallback(TossPayCallbackRequest request) {
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(
request == null ? null : request.orderNo(),
request == null ? null : request.payToken(),
request == null ? null : request.amount()
);
try (var ignored = LoggingContext.with("payment.callback.received", null, paymentContext)) {
Expand Down Expand Up @@ -436,7 +434,6 @@ private void validateTossResponse(Long userId, PaymentConfirmRequest request, To
String easyPayProvider = response.easyPay() == null ? null : response.easyPay().provider();
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(
request.orderId(),
request.paymentKey(),
userId,
null,
request.amount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String storeId() {
public PortOnePaymentResponse getPayment(String paymentId) {
ensureConfigured();
ensureRequestValue(paymentId, "paymentId");
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(paymentId, null, null);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(paymentId, null);
try (var ignored = LoggingContext.with("payment.portone.status.external_called", null, paymentContext)) {
log.info("Calling PortOne get payment API");
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public PortOnePaymentResponse getPayment(String paymentId) {
public PortOneCancelResponse cancelPayment(String paymentId, int amount, String reason) {
ensureConfigured();
ensureRequestValue(paymentId, "paymentId");
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(paymentId, null, amount);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(paymentId, amount);
try (var ignored = LoggingContext.with("payment.portone.refund.external_called", null, paymentContext)) {
log.info("Calling PortOne cancel payment API");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void init() {

public TossPayCreateResponse createPayment(String orderNo, int amount, String productDesc) {
ensureCreatePaymentConfigured();
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderNo, null, amount);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderNo, amount);
try (var ignored = LoggingContext.with("payment.create.external_called", null, paymentContext)) {
log.info("Calling Toss Pay create payment API");
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public TossPayRefundResponse refundPayment(
String reason
) {
ensureRefundConfigured(payToken, orderNo, refundNo);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderNo, payToken, amount);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderNo, amount);
try (var ignored = LoggingContext.with("payment.tosspay.refund.external_called", null, paymentContext)) {
log.info("Calling Toss Pay refund API");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public TossPaymentConfirmResponse confirm(String paymentKey, String orderId, int
if (secretKey == null || secretKey.isBlank()) {
throw new GeneralException(GeneralErrorCode.PAYMENT_CONFIRM_FAILED, "토스페이먼츠 시크릿 키가 설정되지 않았습니다.");
}
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderId, paymentKey, amount);
Map<String, String> paymentContext = PaymentLogMasking.paymentContext(orderId, amount);
try (var ignored = LoggingContext.with("payment.confirm.external_called", null, paymentContext)) {
log.info("Calling Toss payment confirm API");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ app:
logging:
path: ${APP_LOG_PATH:/var/log/spring-boot}
audit-path: ${APP_AUDIT_LOG_PATH:/var/log/spring-boot/audit}
environment: ${APP_LOG_ENVIRONMENT:production}
oauth2:
redirect-uri: ${APP_OAUTH2_REDIRECT_URI}
worker:
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ app:
logging:
path: ${APP_LOG_PATH:logs}
audit-path: ${APP_AUDIT_LOG_PATH:logs/audit}
environment: ${APP_LOG_ENVIRONMENT:local}
request-id-max-length: ${APP_LOG_REQUEST_ID_MAX_LENGTH:64}
trusted-proxies: ${APP_LOG_TRUSTED_PROXIES:}
47 changes: 39 additions & 8 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<springProperty scope="context" name="APP_NAME" source="spring.application.name" defaultValue="jobdri-api" />
<springProperty scope="context" name="LOG_PATH" source="app.logging.path" defaultValue="logs" />
<springProperty scope="context" name="AUDIT_LOG_PATH" source="app.logging.audit-path" defaultValue="logs/audit" />
<springProperty scope="context" name="APP_ENVIRONMENT" source="app.logging.environment" defaultValue="local" />

<property name="APPLICATION_LOG_FILE" value="${LOG_PATH}/application.log" />
<property name="AUDIT_LOG_FILE" value="${AUDIT_LOG_PATH}/audit.log" />
Expand All @@ -11,12 +12,42 @@
name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg %mdc%n%ex{full}" />

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<springProfile name="prod">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>Asia/Seoul</timeZone>
<includeMdc>true</includeMdc>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
<includeMdcKeyName>requestId</includeMdcKeyName>
<includeMdcKeyName>method</includeMdcKeyName>
<includeMdcKeyName>uri</includeMdcKeyName>
<includeMdcKeyName>logType</includeMdcKeyName>
<includeMdcKeyName>event</includeMdcKeyName>
<includeMdcKeyName>errorCode</includeMdcKeyName>
<includeMdcKeyName>taskId</includeMdcKeyName>
<includeMdcKeyName>messageId</includeMdcKeyName>
<includeMdcKeyName>taskType</includeMdcKeyName>
<includeMdcKeyName>retryCount</includeMdcKeyName>
<includeMdcKeyName>workerId</includeMdcKeyName>
<includeMdcKeyName>queueLatencyMillis</includeMdcKeyName>
<customFields>{"service":"${APP_NAME}","service_name":"${APP_NAME}","environment":"${APP_ENVIRONMENT}"}</customFields>
<fieldNames>
<timestamp>timestamp</timestamp>
<logger>logger_name</logger>
<thread>thread</thread>
<stackTrace>stack_trace</stackTrace>
</fieldNames>
</encoder>
</appender>
</springProfile>

<springProfile name="!prod">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
</springProfile>

<appender name="APPLICATION_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${APPLICATION_LOG_FILE}</file>
Expand All @@ -29,7 +60,7 @@
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>Asia/Seoul</timeZone>
<includeMdc>true</includeMdc>
<customFields>{"service":"${APP_NAME}"}</customFields>
<customFields>{"service":"${APP_NAME}","service_name":"${APP_NAME}","environment":"${APP_ENVIRONMENT}"}</customFields>
<fieldNames>
<timestamp>timestamp</timestamp>
<logger>logger_name</logger>
Expand All @@ -50,7 +81,7 @@
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>Asia/Seoul</timeZone>
<includeMdc>true</includeMdc>
<customFields>{"service":"${APP_NAME}"}</customFields>
<customFields>{"service":"${APP_NAME}","service_name":"${APP_NAME}","environment":"${APP_ENVIRONMENT}"}</customFields>
<fieldNames>
<timestamp>timestamp</timestamp>
<logger>logger_name</logger>
Expand Down
Loading