Skip to content

Commit 4c8ba18

Browse files
authored
feat/LS-34 : 로깅 및 yml 통합 (#43)
* del: 안쓰는 파일 삭제 * feat: logback 설정 * feat: aop 로깅 구현 * feat: yml 세팅 및 cd 수정
1 parent ef31229 commit 4c8ba18

File tree

15 files changed

+401
-159
lines changed

15 files changed

+401
-159
lines changed

.github/workflows/ci-cd-compose.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ jobs:
109109
- name: Checkout sources
110110
uses: actions/checkout@v4
111111

112-
- name: Create application.yaml file
112+
- name: Create application-secret.properties file
113113
run: |
114-
echo "${{ secrets.APPLICATION_YAML_API }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application.yaml
114+
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
115115
116116
- name: Send Docker Compose
117117
uses: appleboy/[email protected]
@@ -132,6 +132,6 @@ jobs:
132132
port: 22
133133
script: |
134134
cd /home/${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}
135-
echo "${{ secrets.APPLICATION_YAML_API }}" > application.yaml
136-
docker compose pull
137-
docker compose up -d
135+
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > application-secret.properties
136+
docker-compose pull
137+
docker-compose up -d

.github/workflows/ci-cd.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ project(":layer-api") {
8888

8989
// mysql
9090
runtimeOnly 'com.mysql:mysql-connector-j'
91+
92+
// aop
93+
implementation 'org.springframework.boot:spring-boot-starter-aop'
9194
}
9295

9396
jar.enabled = false

layer-api/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
FROM openjdk:17
22

33
ARG JAR_FILE=./build/libs/*.jar
4+
ARG SPRING_PROFILE
45

56
COPY ${JAR_FILE} layer-server.jar
67

8+
ENV SPRING_PROFILE=${SPRING_PROFILE}
79

8-
ENTRYPOINT ["java","-Dspring.profiles.active=prod" ,"-jar" ,"layer-server.jar"]
10+
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul" ,"-jar" ,"layer-server.jar"]

layer-api/infra/development/docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ services:
44
container_name: layer-api
55
ports:
66
- "8080:8080"
7+
environment:
8+
- TZ=Asia/Seoul
9+
- SPRING_PROFILES_ACTIVE=dev
710
volumes:
8-
- ./application.yaml:/config/application.yaml
11+
- ./application-secret.properties:/config/application-secret.properties
912
networks:
1013
- app-network
1114

layer-api/infra/production/docker-compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ services:
1414
- redis
1515
ports:
1616
- "8080:8080"
17+
environment:
18+
- TZ=Asia/Seoul
19+
- SPRING_PROFILES_ACTIVE=prod
1720
volumes:
1821
- type: bind
1922
source: ./config/application.yaml

layer-api/src/main/java/org/layer/LayerApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import io.swagger.v3.oas.annotations.servers.Server;
66
import org.springframework.boot.SpringApplication;
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.EnableAspectJAutoProxy;
89
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
910

1011
@OpenAPIDefinition(servers = {
1112
@Server(url = "https://api.layerapp.io", description = "운영서버"),
1213
@Server(url = "http://localhost:8080", description = "개발서버")})
1314
@SpringBootApplication
1415
@EnableJpaAuditing
16+
@EnableAspectJAutoProxy
1517
public class LayerApplication {
1618
public static void main(String[] args) {
1719
SpringApplication.run(LayerApplication.class, args);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.layer.aop;
2+
3+
import java.util.Objects;
4+
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.springframework.security.core.Authentication;
9+
import org.springframework.security.core.context.SecurityContextHolder;
10+
import org.springframework.stereotype.Component;
11+
import org.springframework.util.StopWatch;
12+
import org.springframework.web.bind.annotation.RequestMethod;
13+
import org.springframework.web.context.request.RequestContextHolder;
14+
import org.springframework.web.context.request.ServletRequestAttributes;
15+
16+
import jakarta.servlet.http.HttpServletRequest;
17+
import lombok.extern.log4j.Log4j2;
18+
19+
@Aspect
20+
@Component
21+
@Log4j2
22+
public class ExecutionLoggingAop {
23+
24+
// 모든 layer-api 모듈 내의 controller package에 존재하는 클래스
25+
@Around("execution(* org.layer.domain..controller..*(..))")
26+
public Object logExecutionTrace(ProceedingJoinPoint pjp) throws Throwable {
27+
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
28+
RequestMethod httpMethod = RequestMethod.valueOf(request.getMethod());
29+
30+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
31+
Long memberId = null;
32+
if (!authentication.getPrincipal().equals("anonymousUser")) {
33+
memberId = (Long) authentication.getPrincipal();
34+
}
35+
36+
String className = pjp.getSignature().getDeclaringType().getSimpleName();
37+
String methodName = pjp.getSignature().getName();
38+
String task = className + "." + methodName;
39+
40+
log.info("[Call Method] " + httpMethod + ": " + task + " | Request userId=" + memberId);
41+
42+
Object[] paramArgs = pjp.getArgs();
43+
String loggingMessage = "";
44+
int cnt = 1;
45+
for (Object object : paramArgs) {
46+
if (Objects.nonNull(object)) {
47+
String paramName = "[param" + cnt +"] " + object.getClass().getSimpleName();
48+
String paramValue = " [value" + cnt +"] " + object;
49+
loggingMessage += paramName + paramValue + "\n";
50+
cnt++;
51+
}
52+
}
53+
log.info("{}", loggingMessage);
54+
// 해당 클래스 처리 전의 시간
55+
StopWatch sw = new StopWatch();
56+
sw.start();
57+
58+
Object result = null;
59+
60+
// 해당 클래스의 메소드 실행
61+
try{
62+
result = pjp.proceed();
63+
}
64+
catch (Exception e){
65+
log.warn("[ERROR] " + task + " 메서드 예외 발생 : " + e.getMessage());
66+
throw e;
67+
}
68+
69+
// 해당 클래스 처리 후의 시간
70+
sw.stop();
71+
long executionTime = sw.getTotalTimeMillis();
72+
73+
log.info("[ExecutionTime] " + task + " --> " + executionTime + " (ms)");
74+
75+
return result;
76+
}
77+
78+
}

layer-api/src/main/java/org/layer/filter/LoggerFilter.java

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
spring:
2+
config:
3+
import: application-secret.properties
4+
datasource:
5+
url: ${DEV_DB_URL}
6+
username: ${DEV_DB_NAME}
7+
password: ${DEV_DB_PASSWORD}
8+
driver-class-name: com.mysql.cj.jdbc.Driver
9+
jpa:
10+
hibernate:
11+
ddl-auto: update
12+
properties:
13+
hibernate:
14+
format_sql: true
15+
show_sql: true
16+
open-in-view: false
17+
database: mysql
18+
19+
data:
20+
redis:
21+
host: ${DEV_REDIS_HOST}
22+
port: ${DEV_REDIS_PORT}
23+
password: ${DEV_REDIS_PASSWORD}
24+
25+
jwt:
26+
secret: ${DEV_JWT_SECRET}
27+
28+
kakao:
29+
login:
30+
api_key: ${DEV_KAKAO_API_KEY}
31+
redirect_uri: ${DEV_KAKAO_REDIRECT_URI}
32+
uri:
33+
base: https://kauth.kakao.com
34+
code: /oauth/authorize
35+
token: /oauth/token
36+
api:
37+
uri:
38+
base: https://kapi.kakao.com
39+
user: /v2/user/me
40+
41+
google:
42+
login:
43+
client_id: ${DEV_GOOGLE_CLIENT_ID}
44+
code_uri: ${DEV_GOOGLE_CODE_URI}
45+
token_uri: ${DEV_GOOGLE_TOKEN_URI}
46+
client_secret: ${DEV_GOOGLE_CLIENT_SECRET}
47+
redirect_uri: ${DEV_GOOGLE_REDIRECT_URI}
48+
code_redirect_uri: http://localhost:8080/api/auth/oauth2/google/code
49+
50+
51+
webmvc:
52+
cors:
53+
allowedOrigins:
54+
http://localhost:8080,
55+
https://api.layerapp.io,
56+
https://layerapp.io,
57+
http://localhost:5173
58+
59+
ncp:
60+
storage:
61+
region: ${STORAGE_REGION}
62+
bucketName: ${STORAGE_NAME}
63+
endpoint: ${STORAGE_ENDPOINT}
64+
accessKey: ${STORAGE_ACCESS_KEY}
65+
secretKey: ${STORAGE_SECRET_KEY}

0 commit comments

Comments
 (0)