-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from woowacourse-teams/dev/be
로그 및 액션 파일 최신화를 위한 PR
- Loading branch information
Showing
24 changed files
with
397 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,32 @@ name: Backend CI | |
on: | ||
pull_request: | ||
branches: | ||
- '**' | ||
- dev/be | ||
- develop | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
build-directory: ./backend | ||
runs-on: self-hosted | ||
|
||
steps: | ||
- name: Checkout | ||
- name: 체크아웃 | ||
uses: actions/checkout@v4 | ||
- name: Start MySQL | ||
uses: mirromutth/[email protected] | ||
with: | ||
host port: 23306 | ||
container port: 3306 | ||
mysql version: lts | ||
mysql database: code_zap | ||
mysql root password: woowacourse | ||
- name: Setup JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: temurin | ||
- name: Test with Gradle Wrapper | ||
|
||
- name: H2 스프링 설정 생성 | ||
run: | | ||
echo "spring: | ||
h2: | ||
console: | ||
enabled: true | ||
path: /h2-console | ||
datasource: | ||
url: jdbc:h2:mem:database" > backend/src/main/resources/application.yml | ||
- name: 테스트 코드 실행 | ||
run: ./gradlew test | ||
working-directory: ${{ env.build-directory }} | ||
working-directory: ./backend | ||
|
||
- name: 클린업 | ||
if: always() | ||
run: rm -rf ../2024-code-zap/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,4 +156,3 @@ JWT와 리프레시 토큰으로 로그인 기능을 구현해야 하는 순간, | |
</table> | ||
|
||
<br> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ out/ | |
|
||
### macOS ### | ||
.DS_Store | ||
|
||
### YAML ### | ||
application-db.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/codezap/global/logger/MDCFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package codezap.global.logger; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
|
||
import org.slf4j.MDC; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
public class MDCFilter implements Filter { | ||
private final String CORRELATION_ID = "correlationId"; | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
MDC.put(CORRELATION_ID, generateCorrelationId()); | ||
chain.doFilter(request, response); | ||
MDC.clear(); | ||
} | ||
|
||
private String generateCorrelationId() { | ||
return UUID.randomUUID() | ||
.toString() | ||
.substring(0, 8); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/codezap/global/logger/MethodExecutionTimeAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codezap.global.logger; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Aspect | ||
@Component | ||
public class MethodExecutionTimeAspect { | ||
|
||
@Around("execution(* codezap..*(..)) && " + | ||
"!execution(* codezap.global.logger.MethodExecutionTimeAspect(..))" + | ||
"!execution(* codezap.global.exception.*.*(..))") | ||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { | ||
if (!log.isInfoEnabled()) { | ||
return joinPoint.proceed(); | ||
} | ||
|
||
long startTime = System.currentTimeMillis(); | ||
Object result = joinPoint.proceed(); | ||
long endTime = System.currentTimeMillis(); | ||
|
||
long executionTimeMillis = endTime - startTime; | ||
|
||
String className = joinPoint.getSignature() | ||
.getDeclaringType() | ||
.getSimpleName(); | ||
String methodName = joinPoint.getSignature() | ||
.getName(); | ||
|
||
log.info("{}.{} 실행 {}ms", className, methodName, executionTimeMillis); | ||
|
||
return result; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
backend/src/main/java/codezap/global/logger/RequestResponseLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package codezap.global.logger; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
import org.springframework.web.util.ContentCachingRequestWrapper; | ||
import org.springframework.web.util.ContentCachingResponseWrapper; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
public class RequestResponseLogger extends OncePerRequestFilter { | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request); | ||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
filterChain.doFilter(requestWrapper, responseWrapper); | ||
long duration = System.currentTimeMillis() - startTime; | ||
|
||
String requestBody = new String(requestWrapper.getContentAsByteArray(), StandardCharsets.UTF_8); | ||
String responseBody = new String(responseWrapper.getContentAsByteArray(), StandardCharsets.UTF_8); | ||
|
||
log.info("[Request] {}, {}, 요청 바디: {}", request.getMethod(), request.getRequestURI(), requestBody); | ||
log.info("[Response] Status: {}, Duration: {}ms, 응답 바디: {}", response.getStatus(), duration, responseBody); | ||
|
||
responseWrapper.copyBodyToResponse(); | ||
} | ||
|
||
@Override | ||
protected boolean shouldNotFilter(HttpServletRequest request) { | ||
String path = request.getRequestURI(); | ||
return path.contains("/swagger") || path.contains("/v3/api-docs"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package codezap.member.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class Member { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(unique = true, nullable = false) | ||
private String email; | ||
|
||
@Column(nullable = false) | ||
private String password; | ||
|
||
@Column(unique = true, nullable = false) | ||
private String username; | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/codezap/member/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package codezap.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import codezap.member.domain.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.