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] Prod 환경 로그 설정 #201

Merged
merged 16 commits into from
Aug 19, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/be-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: ./gradlew bootJar

- name: Stop existing Java Application
run: ps -ef | grep 'ddangkong-0.0.1-SNAPSHOT.jar' | awk '{print $2}' | xargs sudo kill -15
run: ps -ef | grep 'java -jar' | awk '{print $2}' | xargs sudo kill -15 || true

- name: Start Java Application
run: sudo nohup java -jar ddangkong-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod &
run: sudo nohup java -jar -Dspring.profiles.active=prod ./build/libs/ddangkong-0.0.1-SNAPSHOT.jar &
5 changes: 5 additions & 0 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ server:
cors:
origin: ${secret.cors.origin}

logging:
config: classpath:logback-prod.xml
discord:
webhook-url: ${secret.discord.webhook-url}
location: ${secret.application.log.location}
48 changes: 48 additions & 0 deletions backend/src/main/resources/logback-prod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- ddangkong 패키지에 대한 로그를 파일에 출력하기 위한 설정 -->
<springProperty name="LOG_HOME_PATH" source="logging.location"/>
<property name="LOG_PATH" value="${LOG_HOME_PATH}/app-logs"/>
<appender name="DDANGKONG_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/ddangkong.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/ddangkong-%d{yyyy-MM-dd}.log</fileNamePattern> <!-- 매일 새로운 파일 생성 -->
<maxHistory>365</maxHistory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문)
1년인 이유가 있나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 운영 환경의 로그는 (개발 환경 보다는) 길게 해야 한다고 생각합니다. 그래서 사용자의 불편함 등을 더 많은 정보로 트래킹 할 수 있기 때문이죠.

그렇다고 딱 1년인 이유는 없습니다. 더 길면 길수록 좋다고 생각하는데, 하드 용량을 생각해서 대충 1년 설정했습니다. 트래킹 하면서 조정해봐야 될 것 같습니다.

</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss,Asia/Seoul} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- Discord Webhook 설정 -->
<springProperty name="DISCORD_WEBHOOK_URL" source="logging.discord.webhook-url"/>
<appender name="DISCORD" class="com.github.napstr.logback.DiscordAppender">
<webhookUri>${DISCORD_WEBHOOK_URL}</webhookUri>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss,Asia/Seoul} [%thread] [%-5level] %logger{36} - %msg%n```%ex{full}```
</pattern>
</layout>
<username>prod-error-alert-bot</username>
<avatarUrl>
https://velog.velcdn.com/images/gwichanlee/post/c03a74cc-07fd-45ee-bfff-7b5147522f89/image.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) 요 사진은 정말 그대로 가시나요 ㅋㅋㅋ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭐 개발 환경에서도 잘 사용하는데요 ㅋㅋ

해당 정보는 사용자한테 노출 안되는 정보라 크게 상관 없을 것 같아요~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 좋아요 ㅋㅋㅋㅋㅋ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

노출되면 인플루언서로 전직하죠

</avatarUrl>
<tts>false</tts>
</appender>

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

<!-- ddangkong 하위 패키지의 logger 설정 -->
<logger name="ddangkong" level="INFO" additivity="false">
<appender-ref ref="DDANGKONG_LOG"/>
<appender-ref ref="ASYNC_DISCORD"/>
</logger>

<!-- root logger 설정 -->
<root level="OFF">
</root>
</configuration>