Skip to content

Commit

Permalink
[BYOB-114] Logback에서 AWS CloudWatch에 로그 출력하도록 설정 (#27)
Browse files Browse the repository at this point in the history
* feat: logback 설정 및 cloudwatch 환경변수 세팅

* test: logback-cloudwatch 연결 테스트 workflow 작성

* fix: logback-spring.xml의 property를 springProperty로 수정

* fix: 로그 시간 형식 수정

* feat: test workflow 삭제
  • Loading branch information
y-ngm-n authored Jul 29, 2024
1 parent fb2663f commit 478dbce
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ dependencies {
// AWS Cloud
implementation 'io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.4.4'

// AWS CloudWatch logback appender
implementation "ca.pjer:logback-awslogs-appender:1.6.0"

// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ server.servlet.context-path=/api/v1
service.url=https://dev.jumo.im

# Swagger settings
springdoc.swagger-ui.enabled=false
springdoc.api-docs.enabled=false
#springdoc.swagger-ui.enabled=false
#springdoc.api-docs.enabled=false

# Kakao OAuth2 settings
spring.security.oauth2.client.registration.kakao.client-name=${KAKAO_CLIENT_NAME}
Expand Down Expand Up @@ -34,4 +34,9 @@ spring.datasource.driver-class-name=${DB_DRIVER}
# Hibernate settings
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

# AWS CloudWatch Configuration
cloudwatch.name=jumo-server-dev-lg
cloudwatch.accesskey=${LOGGER_ACCESS}
cloudwatch.secretkey=${LOGGER_SECRET}
7 changes: 6 additions & 1 deletion src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ spring.datasource.driver-class-name=${DB_DRIVER}
# Hibernate settings
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

# AWS CloudWatch Configuration
cloudwatch.name=jumo-server-dev-lg
cloudwatch.accesskey=${LOGGER_ACCESS}
cloudwatch.secretkey=${LOGGER_SECRET}
39 changes: 39 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<configuration timeZone="Asia/Seoul">
<!-- 기본 콘솔 출력 설정 -->
<springProfile name="default,local">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>

<!-- 개발 환경 로깅 설정 -->
<springProfile name="dev">
<springProperty name="name" source="cloudwatch.name" />
<springProperty name="accesskey" source="cloudwatch.accesskey" />
<springProperty name="secretkey" source="cloudwatch.secretkey" />

<appender name="aws_cloudwatch_log" class="ca.pjer.logback.AwsLogsAppender">
<layout>
<pattern>[%thread] [%date{yyyy-MM-dd HH:mm:ss}] [%level] [%file:%line] - %msg%n</pattern>
</layout>
<logGroupName>${name}</logGroupName>
<logStreamUuidPrefix>jumo-server-dev/</logStreamUuidPrefix>
<logRegion>ap-northeast-2</logRegion>
<maxBatchLogEvents>50</maxBatchLogEvents>
<maxFlushTimeMillis>60000</maxFlushTimeMillis>
<maxBlockTimeMillis>5000</maxBlockTimeMillis>
<retentionTimeDays>0</retentionTimeDays>
<accessKeyId>${accesskey}</accessKeyId>
<secretAccessKey>${secretkey}</secretAccessKey>
</appender>

<root level="INFO">
<appender-ref ref="aws_cloudwatch_log"/>
</root>
</springProfile>
</configuration>

0 comments on commit 478dbce

Please sign in to comment.