Skip to content

Commit

Permalink
feat: 슬랙 알림 채널 연동 (#91)
Browse files Browse the repository at this point in the history
* feat: 슬랙 알림 채널 연동

* feat: properties.xml 추가

* chore: webhook uri 재생성 및 노출 제외

* feat: prod logback 분리
  • Loading branch information
songyi00 authored Nov 10, 2024
1 parent f55db8a commit 2077ef2
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
export OBJECT_STORAGE_ACCESS_KEY_ID=${{ secrets.OBJECT_STORAGE_ACCESS_KEY_ID }}
export OBJECT_STORAGE_SECRET_KEY=${{ secrets.OBJECT_STORAGE_SECRET_KEY }}
export ENCODED_FIREBASE_ADMIN_SDK=${{ secrets.ENCODED_FIREBASE_ADMIN_SDK }}
export SLACK_WEBHOOK_URI=${{ secrets.SLACK_WEBHOOK_URI }}
sudo docker rm -f $(docker ps -qa)
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ dependencies {
// firebase
implementation 'com.google.firebase:firebase-admin:9.3.0'

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

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
OBJECT_STORAGE_ACCESS_KEY_ID: ${OBJECT_STORAGE_ACCESS_KEY_ID}
OBJECT_STORAGE_SECRET_KEY: ${OBJECT_STORAGE_SECRET_KEY}
ENCODED_FIREBASE_ADMIN_SDK: ${ENCODED_FIREBASE_ADMIN_SDK}
SLACK_WEBHOOK_URI: ${SLACK_WEBHOOK_URI}
restart: always
volumes:
- ./logs:/logs
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/nexters/goalpanzi/GoalpanziApplication.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.nexters.goalpanzi;

import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.TimeZone;

@SpringBootApplication
public class GoalpanziApplication {

public static void main(String[] args) {
SpringApplication.run(GoalpanziApplication.class, args);
}
public static void main(String[] args) {
var ctx = SpringApplication.run(GoalpanziApplication.class, args);
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
var serverPort = ctx.getEnvironment().getProperty("server.port");
var profile = ctx.getEnvironment().getProperty("spring.profiles.active");

// startup notification
String banner = String.format("GoalpanziApplication started (profile=%s, port=%s)", profile, serverPort);
System.out.println(banner);
LoggerFactory.getLogger("ServerBoot").info(banner);
}
}
34 changes: 34 additions & 0 deletions src/main/resources/appenders/slack-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<included>
<appender name="SLACK" class="com.github.maricn.logback.SlackAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
[%thread] %-5level traceId:"%X{traceId:-}" spanId:"%X{spanId:-}"%n%msg%n
</pattern>
</layout>
<webhookUri>${SLACK_WEBHOOK_URI}</webhookUri>
<username>${SLACK_USERNAME}</username>
<channel>${SLACK_CHANNEL}</channel>
<iconEmoji>:bell:</iconEmoji>
<colorCoding>true</colorCoding>
</appender> <!-- Currently recommended way of using Slack 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="BOOT-SLACK" class="com.github.maricn.logback.SlackAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
*Server Name:* `${HOSTNAME:-}` %n%msg%n
</pattern>
</layout>
<webhookUri>${SLACK_WEBHOOK_URI}</webhookUri>
<username>${SLACK_USERNAME}</username>
<channel>${SLACK_CHANNEL}</channel>
<iconEmoji>:bell:</iconEmoji>
<colorCoding>true</colorCoding>
</appender>
</included>
2 changes: 2 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ oauth:
iss: https://appleid.apple.com
client-id: ${OAUTH_APPLE_CLIENT_ID}

logging:
config: classpath:logback-prod.xml
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
server:
port: 8080

spring:
h2:
console:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="properties.xml"/>
<include resource="appenders/slack-appender.xml"/>

<property name="COLORED_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss} %green([%thread]) %highlight(%5level) %yellow(%logger{36}) - %msg%n"/>
Expand Down Expand Up @@ -36,5 +38,10 @@
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ASYNC-SLACK"/>
</root>

<logger name="ServerBoot" level="INFO">
<appender-ref ref="BOOT-SLACK"/>
</logger>
</configuration>
4 changes: 4 additions & 0 deletions src/main/resources/properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<included>
<property name="SLACK_USERNAME" value="monitor-mission-mate"/>
<property name="SLACK_CHANNEL" value="mission-mate-live"/>
</included>

0 comments on commit 2077ef2

Please sign in to comment.