Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Setting logback #15

Merged
merged 3 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: ShowPot-CI
name: ShowPot-Dev-CI

on:
pull_request:
branches:
- develop
- prod

jobs:
build:
Expand All @@ -24,6 +23,14 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Copy Secrets
env:
ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
run:
echo $ACCESS_KEY > ./app/src/main/resources/application-dev.yml
echo $SECRET_KEY > ./app/src/main/resources/application-dev.yml

- name: Build with Gradle Wrapper
run: ./gradlew clean build

Expand All @@ -42,8 +49,8 @@ jobs:
uses: sarisia/actions-status-discord@v1
if: failure()
with:
title: โ—๏ธBackend CI failed โ—๏ธ
webhook: ${{ secrets.DISCORD_WEBHOOK }}
color: FF0000
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_FAILED_AVATAR_URL }}
title: โ—๏ธBackend CI failed โ—๏ธ
webhook: ${{ secrets.DISCORD_WEBHOOK }}
color: FF0000
GaBaljaintheroom marked this conversation as resolved.
Show resolved Hide resolved
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_FAILED_AVATAR_URL }}
56 changes: 56 additions & 0 deletions .github/workflows/showPot-prod-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: ShowPot-Prod-CI

on:
pull_request:
branches:
- prod

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'liberica'
cache: gradle

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Copy Secrets
env:
ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
run:
echo $ACCESS_KEY > ./app/src/main/resources/application-prod.yml
echo $SECRET_KEY > ./app/src/main/resources/application-prod.yml

- name: Build with Gradle Wrapper
run: ./gradlew clean build

- name: Backend CI Discord Notification
uses: sarisia/actions-status-discord@v1
if: success()
with:
title: โœ… Backend CI success โœ…
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
content: "<@1084774841460215839> <@281597829636423682> ShoPot ์ด์Šˆ ํ˜น์€ PR์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”!"
color: 00FF00
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_SUCCESS_AVATAR_URL }}

- name: Backend CI Discord Notification
uses: sarisia/actions-status-discord@v1
if: failure()
with:
title: โ—๏ธBackend CI failed โ—๏ธ
webhook: ${{ secrets.DISCORD_WEBHOOK }}
color: FF0000
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_FAILED_AVATAR_URL }}
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ dependencies {
// docker-compose
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
testAndDevelopmentOnly 'org.springframework.boot:spring-boot-docker-compose'

// aws logs
implementation 'ca.pjer:logback-awslogs-appender:1.6.0'
}
6 changes: 6 additions & 0 deletions app/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ spring:
docker:
compose:
enabled: false

cloud:
aws:
credentials:
accessKey: ${ACCESS_KEY}
secretKey: ${SECRET_KEY}
8 changes: 7 additions & 1 deletion app/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
spring:
docker:
compose:
enabled: false
enabled: false

cloud:
aws:
credentials:
accessKey: ${ACCESS_KEY}
secretKey: ${SECRET_KEY}
59 changes: 59 additions & 0 deletions app/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<conversionRule conversionWord="clr"
converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>

<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>

<springProperty name="ACTIVE_PROFILE" source="spring.profiles.active"/>
<springProperty name="AWS_ACCESS_KEY" source="cloud.aws.credentials.accessKey"/>
<springProperty name="AWS_SECRET_KEY" source="cloud.aws.credentials.secretKey"/>

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>

<appender name="CloudWatchAppender" class="ca.pjer.logback.AwsLogsAppender">
<layout>
<pattern>[%thread] [%date] [%level] [%file:%line] - %msg%n</pattern>
</layout>
<!-- Information of Cloudwatch -->
<logGroupName>showpot/${ACTIVE_PROFILE}</logGroupName>
<logRegion>ap-northeast-2</logRegion>
<maxBatchLogEvents>50</maxBatchLogEvents>
<maxFlushTimeMillis>60000</maxFlushTimeMillis>
<maxBlockTimeMillis>5000</maxBlockTimeMillis>
<retentionTimeDays>0</retentionTimeDays>
<accessKeyId>${AWS_ACCESS_KEY}</accessKeyId>
<secretAccessKey>${AWS_SECRET_KEY}</secretAccessKey>

<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>

<encoder>
<charset>UTF-8</charset>
<pattern>%d{HH:mm:ss.SSS} [%thread] [%5level] %logger{35}[%method:%line] %m%n</pattern>
</encoder>
</appender>

<springProfile name="local, dev, prod">
<root level="INFO">
<appender-ref ref="Console"/>
</root>
</springProfile>

<springProfile name="dev, prod">
<root level="WARN">
<appender-ref ref="CloudWatchAppender"/>
</root>
</springProfile>
</configuration>