From b78f24efbe4d91b04c1fa49e5b0e32f09fef4792 Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 15:30:23 +0900 Subject: [PATCH 1/6] =?UTF-8?q?#263=20[feat]=20mdc=20filter=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/log/MDCLoggingFilter.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/kotlin/com/photi/server/common/log/MDCLoggingFilter.kt diff --git a/src/main/kotlin/com/photi/server/common/log/MDCLoggingFilter.kt b/src/main/kotlin/com/photi/server/common/log/MDCLoggingFilter.kt new file mode 100644 index 00000000..842fcf82 --- /dev/null +++ b/src/main/kotlin/com/photi/server/common/log/MDCLoggingFilter.kt @@ -0,0 +1,31 @@ +package com.photi.server.common.log + +import jakarta.servlet.Filter +import jakarta.servlet.FilterChain +import jakarta.servlet.ServletRequest +import jakarta.servlet.ServletResponse +import org.slf4j.MDC +import org.springframework.core.Ordered +import org.springframework.core.annotation.Order +import org.springframework.stereotype.Component +import java.util.* + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +class MDCLoggingFilter : Filter { + + override fun doFilter( + request: ServletRequest, + response: ServletResponse, + filterChain: FilterChain, + ) { + val uuid = UUID.randomUUID() + MDC.put(REQUEST_ID, uuid.toString()) + filterChain.doFilter(request, response) + MDC.clear() + } + + companion object { + const val REQUEST_ID = "request_id" + } +} From d8e6daab658c91c3b9266caea91c0bf5570e986c Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 15:31:16 +0900 Subject: [PATCH 2/6] =?UTF-8?q?#263=20[feat]=20=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EB=B9=84=EB=8F=99=EA=B8=B0=20context=20=EC=9C=A0=EC=A7=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/log/LoggingTaskDecorator.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/kotlin/com/photi/server/common/log/LoggingTaskDecorator.kt diff --git a/src/main/kotlin/com/photi/server/common/log/LoggingTaskDecorator.kt b/src/main/kotlin/com/photi/server/common/log/LoggingTaskDecorator.kt new file mode 100644 index 00000000..884a75f0 --- /dev/null +++ b/src/main/kotlin/com/photi/server/common/log/LoggingTaskDecorator.kt @@ -0,0 +1,18 @@ +package com.photi.server.common.log + +import org.slf4j.MDC +import org.springframework.core.task.TaskDecorator + +class LoggingTaskDecorator : TaskDecorator { + + override fun decorate(task: Runnable): Runnable { + val callerThreadContext = MDC.getCopyOfContextMap() + + return Runnable { + callerThreadContext?.let { + MDC.setContextMap(it) + } + task.run() + } + } +} From 1540838407f65e55e8808bfc2987d59376cdc34b Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 15:32:50 +0900 Subject: [PATCH 3/6] =?UTF-8?q?#263=20[refactor]=20graceful=20shutdown=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B0=8F=20=EB=B9=84=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/photi/server/config/AsyncConfig.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/photi/server/config/AsyncConfig.kt b/src/main/kotlin/com/photi/server/config/AsyncConfig.kt index 91fd3add..557541f9 100644 --- a/src/main/kotlin/com/photi/server/config/AsyncConfig.kt +++ b/src/main/kotlin/com/photi/server/config/AsyncConfig.kt @@ -1,24 +1,31 @@ package com.photi.server.config import com.photi.server.common.exception.CustomAsyncUncaughtExceptionHandler +import com.photi.server.common.log.LoggingTaskDecorator import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler import org.springframework.context.annotation.Configuration import org.springframework.scheduling.annotation.AsyncConfigurer import org.springframework.scheduling.annotation.EnableAsync import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor -import java.util.concurrent.Executor +import java.util.concurrent.ThreadPoolExecutor @EnableAsync @Configuration class AsyncConfig : AsyncConfigurer { - override fun getAsyncExecutor(): Executor? { + override fun getAsyncExecutor(): ThreadPoolTaskExecutor { return ThreadPoolTaskExecutor().apply { - corePoolSize = 3 - maxPoolSize = 10 - queueCapacity = 500 + corePoolSize = 10 + queueCapacity = 50 + maxPoolSize = 30 + keepAliveSeconds = 60 setThreadNamePrefix("Executor-") - initialize() + setTaskDecorator(LoggingTaskDecorator()) + setRejectedExecutionHandler(ThreadPoolExecutor.CallerRunsPolicy()) + setWaitForTasksToCompleteOnShutdown(true) + setAwaitTerminationSeconds(20) + setAcceptTasksAfterContextClose(false) + setAllowCoreThreadTimeOut(false) } } From 4f5eb1cb176a9ac2eb4e3c29eaf314a6cd0df5ac Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 15:33:15 +0900 Subject: [PATCH 4/6] =?UTF-8?q?#263=20[chore]=20logback=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback-spring.xml | 47 +++++++++++++++ src/main/resources/logback/dev-logback.xml | 19 ------ src/main/resources/logback/prod-logback.xml | 65 --------------------- 3 files changed, 47 insertions(+), 84 deletions(-) create mode 100644 src/main/resources/logback-spring.xml delete mode 100644 src/main/resources/logback/dev-logback.xml delete mode 100644 src/main/resources/logback/prod-logback.xml diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..a1f7f519 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,47 @@ + + + + + + + + + + ${LOG_PATTERN} + + + + + + ${LOG_PATTERN} + + + ${LOG_PATH}/%d{yyyy-MM-dd}.%i.log + 1 + 200MB + 10MB + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/logback/dev-logback.xml b/src/main/resources/logback/dev-logback.xml deleted file mode 100644 index dc079df9..00000000 --- a/src/main/resources/logback/dev-logback.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){green} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/logback/prod-logback.xml b/src/main/resources/logback/prod-logback.xml deleted file mode 100644 index 295e90e6..00000000 --- a/src/main/resources/logback/prod-logback.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){green} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - ${ROLLING_LOG_FILEPATH}/${ROLLING_LOG_FILENAME}.log - - UTF-8 - - %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){green} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - ${ROLLING_LOG_FILEPATH}/${ROLLING_LOG_FILENAME}_%d{yyyy-MM-dd}_%i.log - - 50MB - - - - - - - error - ACCEPT - DENY - - ${ERROR_LOG_FILEPATH}/${ERROR_LOG_FILENAME}.log - - UTF-8 - - %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){green} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - ${ERROR_LOG_FILEPATH}/${ERROR_LOG_FILENAME}_%d{yyyy-MM-dd}_%i.log - - 100MB - - - - - - - - - - \ No newline at end of file From c68158e5c06a8dfe2b896eaff5e6d24ba23fb45d Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 15:38:27 +0900 Subject: [PATCH 5/6] =?UTF-8?q?#263=20[chore]=20=EB=8F=84=EC=BB=A4-ec2=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=ED=8C=8C=EC=9D=BC=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/dev/docker-compose.yml | 2 ++ docker/prod/docker-compose.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 04bd24e3..e8a90219 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -11,6 +11,8 @@ services: - TZ=Asia/Seoul networks: - server-network + volumes: + - /home/ubuntu/logs:/app/logs redis: image: redis:latest ports: diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index 7f06af2e..f02a53a3 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -5,6 +5,8 @@ services: - .env ports: - "8080:8080" + volumes: + - /home/ubuntu/logs:/app/logs environment: - TZ=Asia/Seoul networks: From 01d6acafb6bb8a47fe30146e9460d5711de562d0 Mon Sep 17 00:00:00 2001 From: YuGyeong98 Date: Sat, 13 Sep 2025 17:18:20 +0900 Subject: [PATCH 6/6] =?UTF-8?q?#263=20[chore]=20=EB=8F=84=EC=BB=A4=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=201.1.2=20=EB=B2=84=EC=A0=84?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/prod/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index f02a53a3..b475d3f8 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -1,6 +1,6 @@ services: backend: - image: yugyeong390/photi-server:1.1.1 + image: yugyeong390/photi-server:1.1.2 env_file: - .env ports: