Skip to content

Commit

Permalink
Merge pull request #109 from LikeKNU/Chore/Logback
Browse files Browse the repository at this point in the history
chore: configure logback pattern and appender by active profiles
  • Loading branch information
jcw1031 authored Jun 2, 2024
2 parents b1923ea + 274e806 commit 2194a7d
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
branches:
- main
# pull_request:
# branches:
# - main

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os: linux

files:
- source: /
destination: /home/ec2-user/deploy
destination: /home/ec2-user/LikeKNU
overwrite: yes

permissions:
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}

Expand Down
14 changes: 7 additions & 7 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash

ROOT_PATH="/home/ec2-user/deploy"
JAR="$ROOT_PATH/application.jar"
ROOT_PATH="/home/ec2-user/LikeKNU"
JAR="$ROOT_PATH/LikeKNU.jar"

APP_LOG="$ROOT_PATH/application.log"
ERROR_LOG="$ROOT_PATH/error.log"
START_LOG="$ROOT_PATH/start.log"

NOW=$(date +%c)

echo "[$NOW] $JAR 복사" >> $START_LOG
cp $ROOT_PATH/build/libs/LikeKNU-1.0.0.jar $JAR
echo "[$NOW] Copy $JAR" >> $START_LOG
cp $ROOT_PATH/build/libs/*.jar $JAR

echo "[$NOW] > $JAR 실행" >> $START_LOG
echo "[$NOW] Run $JAR" >> $START_LOG
source ~/.bash_profile
nohup java -jar $JAR > $APP_LOG 2> $ERROR_LOG &
nohup java -jar $JAR --spring.profiles.active=prod > $APP_LOG 2> $ERROR_LOG &

SERVICE_PID=$(pgrep -f $JAR)
echo "[$NOW] > 서비스 PID: $SERVICE_PID" >> $START_LOG
echo "[$NOW] Application PID: $SERVICE_PID" >> $START_LOG
8 changes: 4 additions & 4 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

ROOT_PATH="/home/ec2-user/deploy"
JAR="$ROOT_PATH/application.jar"
ROOT_PATH="/home/ec2-user/LikeKNU"
JAR="$ROOT_PATH/LikeKNU.jar"
STOP_LOG="$ROOT_PATH/stop.log"
SERVICE_PID=$(pgrep -f $JAR)

if [ -z "$SERVICE_PID" ]; then
echo "서비스 NotFound" >> $STOP_LOG
echo "Service not found" >> $STOP_LOG
else
echo "서비스 종료 " >> $STOP_LOG
echo "Terminate service " >> $STOP_LOG
kill -9 "$SERVICE_PID"
fi
8 changes: 8 additions & 0 deletions src/main/resources/console-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
</included>
20 changes: 20 additions & 0 deletions src/main/resources/file-error-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<included>
<appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEFAULT_DIR}/log/error/error-${BY_DATE}.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_FILE_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEFAULT_DIR}/backup/error/error-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
</included>
20 changes: 20 additions & 0 deletions src/main/resources/file-info-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<included>
<appender name="FILE-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEFAULT_DIR}/log/info/info-${BY_DATE}.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_FILE_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEFAULT_DIR}/backup/info/info-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
</included>
20 changes: 20 additions & 0 deletions src/main/resources/file-warn-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<included>
<appender name="FILE-WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEFAULT_DIR}/log/warn/warn-${BY_DATE}.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_FILE_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEFAULT_DIR}/backup/warn/warn-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
</included>
30 changes: 30 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>

<configuration>
<timestamp key="BY_DATE" datePattern="yyyy-MM-dd" />
<property name="LOG_PATTERN"
value="%green([%d{yyyy-MM-dd HH:mm:ss.SSS}]) %magenta([%22.22thread]) %highlight(%-5level) | %yellow(%50.50logger{50}) | %msg%n" />
<property name="LOG_FILE_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%22.22thread] %-5level | %50.50logger{50} | %msg%n" />
<property name="DEFAULT_DIR" value="/home/ec2-user/LikeKNU" />

<springProfile name="dev">
<include resource="console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</springProfile>

<springProfile name="prod">
<include resource="file-info-appender.xml" />
<include resource="file-warn-appender.xml" />
<include resource="file-error-appender.xml" />

<root level="INFO">
<appender-ref ref="FILE-INFO" />
<appender-ref ref="FILE-WARN" />
<appender-ref ref="FILE-ERROR" />
</root>

</springProfile>
</configuration>

0 comments on commit 2194a7d

Please sign in to comment.