Skip to content

Commit

Permalink
feat: 에러 로그 슬랙 연동 구현 (#237)
Browse files Browse the repository at this point in the history
* chore: logback slack appender 라이브러리 의존성 추가

* feat: 로그 파일 작성
  • Loading branch information
kmebin authored Dec 3, 2023
1 parent a90afcb commit 6232842
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ dependencies {
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.2")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3'

// webflux
// Webflux
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// Slack Webhook
implementation "net.gpedro.integrations.slack:slack-webhook:1.4.0"
implementation 'net.gpedro.integrations.slack:slack-webhook:1.4.0'

// Logback Slack Appender
implementation 'com.github.maricn:logback-slack-appender:1.6.1'

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

@Service
@Slf4j
@RequiredArgsConstructor
public class TossPaymentService {

Expand All @@ -43,7 +45,10 @@ public ConfirmTossPaymentResponse confirm(ConfirmPaymentRequest request) {
.body(BodyInserters.fromValue(request))
.retrieve()
.onStatus(HttpStatusCode::isError, response -> response.bodyToMono(ErrorResponse.class)
.flatMap(error -> Mono.error(new TossPaymentException(error.message()))))
.flatMap(error -> {
log.error("======= toss-payment confirmation error =======\n{}", error);
return Mono.error(new TossPaymentException(error.message()));
}))
.bodyToMono(ConfirmTossPaymentResponse.class)
.block();
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty name="SLACK_WEBHOOK_URL" source="webhook.slack.url"/>

<appender name="SLACK" class="com.github.maricn.logback.SlackAppender">
<webhookUri>${SLACK_WEBHOOK_URL}</webhookUri>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
에러 로그를 수집했습니다 🚓
✅ Timestamp\n%d{yyyy-MM-dd HH:mm:ss}\n 📍 Error Message\n%msg
</pattern>
<colorCoding>true</colorCoding>
</layout>
</appender>

<appender name="ASYNC_SLACK" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="SLACK"/>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
<springProfile name="dev,prod">
<appender-ref ref="ASYNC_SLACK"/>
</springProfile>
</root>
</configuration>

0 comments on commit 6232842

Please sign in to comment.