Skip to content

Commit

Permalink
feat/LS-34 : 로깅 및 yml 통합 (#43)
Browse files Browse the repository at this point in the history
* del: 안쓰는 파일 삭제

* feat: logback 설정

* feat: aop 로깅 구현

* feat: yml 세팅 및 cd 수정
  • Loading branch information
mikekks authored Jul 29, 2024
1 parent ef31229 commit 4c8ba18
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 159 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci-cd-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Create application.yaml file
- name: Create application-secret.properties file
run: |
echo "${{ secrets.APPLICATION_YAML_API }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application.yaml
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
- name: Send Docker Compose
uses: appleboy/[email protected]
Expand All @@ -132,6 +132,6 @@ jobs:
port: 22
script: |
cd /home/${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}
echo "${{ secrets.APPLICATION_YAML_API }}" > application.yaml
docker compose pull
docker compose up -d
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > application-secret.properties
docker-compose pull
docker-compose up -d
87 changes: 0 additions & 87 deletions .github/workflows/ci-cd.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ project(":layer-api") {

// mysql
runtimeOnly 'com.mysql:mysql-connector-j'

// aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

jar.enabled = false
Expand Down
4 changes: 3 additions & 1 deletion layer-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM openjdk:17

ARG JAR_FILE=./build/libs/*.jar
ARG SPRING_PROFILE

COPY ${JAR_FILE} layer-server.jar

ENV SPRING_PROFILE=${SPRING_PROFILE}

ENTRYPOINT ["java","-Dspring.profiles.active=prod" ,"-jar" ,"layer-server.jar"]
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul" ,"-jar" ,"layer-server.jar"]
5 changes: 4 additions & 1 deletion layer-api/infra/development/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ services:
container_name: layer-api
ports:
- "8080:8080"
environment:
- TZ=Asia/Seoul
- SPRING_PROFILES_ACTIVE=dev
volumes:
- ./application.yaml:/config/application.yaml
- ./application-secret.properties:/config/application-secret.properties
networks:
- app-network

Expand Down
3 changes: 3 additions & 0 deletions layer-api/infra/production/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ services:
- redis
ports:
- "8080:8080"
environment:
- TZ=Asia/Seoul
- SPRING_PROFILES_ACTIVE=prod
volumes:
- type: bind
source: ./config/application.yaml
Expand Down
2 changes: 2 additions & 0 deletions layer-api/src/main/java/org/layer/LayerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@OpenAPIDefinition(servers = {
@Server(url = "https://api.layerapp.io", description = "운영서버"),
@Server(url = "http://localhost:8080", description = "개발서버")})
@SpringBootApplication
@EnableJpaAuditing
@EnableAspectJAutoProxy
public class LayerApplication {
public static void main(String[] args) {
SpringApplication.run(LayerApplication.class, args);
Expand Down
78 changes: 78 additions & 0 deletions layer-api/src/main/java/org/layer/aop/ExecutionLoggingAop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.layer.aop;

import java.util.Objects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;

@Aspect
@Component
@Log4j2
public class ExecutionLoggingAop {

// 모든 layer-api 모듈 내의 controller package에 존재하는 클래스
@Around("execution(* org.layer.domain..controller..*(..))")
public Object logExecutionTrace(ProceedingJoinPoint pjp) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
RequestMethod httpMethod = RequestMethod.valueOf(request.getMethod());

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long memberId = null;
if (!authentication.getPrincipal().equals("anonymousUser")) {
memberId = (Long) authentication.getPrincipal();
}

String className = pjp.getSignature().getDeclaringType().getSimpleName();
String methodName = pjp.getSignature().getName();
String task = className + "." + methodName;

log.info("[Call Method] " + httpMethod + ": " + task + " | Request userId=" + memberId);

Object[] paramArgs = pjp.getArgs();
String loggingMessage = "";
int cnt = 1;
for (Object object : paramArgs) {
if (Objects.nonNull(object)) {
String paramName = "[param" + cnt +"] " + object.getClass().getSimpleName();
String paramValue = " [value" + cnt +"] " + object;
loggingMessage += paramName + paramValue + "\n";
cnt++;
}
}
log.info("{}", loggingMessage);
// 해당 클래스 처리 전의 시간
StopWatch sw = new StopWatch();
sw.start();

Object result = null;

// 해당 클래스의 메소드 실행
try{
result = pjp.proceed();
}
catch (Exception e){
log.warn("[ERROR] " + task + " 메서드 예외 발생 : " + e.getMessage());
throw e;
}

// 해당 클래스 처리 후의 시간
sw.stop();
long executionTime = sw.getTotalTimeMillis();

log.info("[ExecutionTime] " + task + " --> " + executionTime + " (ms)");

return result;
}

}
65 changes: 0 additions & 65 deletions layer-api/src/main/java/org/layer/filter/LoggerFilter.java

This file was deleted.

65 changes: 65 additions & 0 deletions layer-api/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
spring:
config:
import: application-secret.properties
datasource:
url: ${DEV_DB_URL}
username: ${DEV_DB_NAME}
password: ${DEV_DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
show_sql: true
open-in-view: false
database: mysql

data:
redis:
host: ${DEV_REDIS_HOST}
port: ${DEV_REDIS_PORT}
password: ${DEV_REDIS_PASSWORD}

jwt:
secret: ${DEV_JWT_SECRET}

kakao:
login:
api_key: ${DEV_KAKAO_API_KEY}
redirect_uri: ${DEV_KAKAO_REDIRECT_URI}
uri:
base: https://kauth.kakao.com
code: /oauth/authorize
token: /oauth/token
api:
uri:
base: https://kapi.kakao.com
user: /v2/user/me

google:
login:
client_id: ${DEV_GOOGLE_CLIENT_ID}
code_uri: ${DEV_GOOGLE_CODE_URI}
token_uri: ${DEV_GOOGLE_TOKEN_URI}
client_secret: ${DEV_GOOGLE_CLIENT_SECRET}
redirect_uri: ${DEV_GOOGLE_REDIRECT_URI}
code_redirect_uri: http://localhost:8080/api/auth/oauth2/google/code


webmvc:
cors:
allowedOrigins:
http://localhost:8080,
https://api.layerapp.io,
https://layerapp.io,
http://localhost:5173

ncp:
storage:
region: ${STORAGE_REGION}
bucketName: ${STORAGE_NAME}
endpoint: ${STORAGE_ENDPOINT}
accessKey: ${STORAGE_ACCESS_KEY}
secretKey: ${STORAGE_SECRET_KEY}
Loading

0 comments on commit 4c8ba18

Please sign in to comment.