From 9a00bb19dcbe4c9e82497d33dd8967a05b159278 Mon Sep 17 00:00:00 2001 From: WrBug Date: Wed, 7 Jan 2026 11:26:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Docker=20=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=97=A5=E5=BF=97=E7=BA=A7=E5=88=AB=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 application.properties 中支持通过 LOG_LEVEL_ROOT 和 LOG_LEVEL_APP 环境变量配置日志级别 - 在 docker-compose.yml 和 docker-compose.prod.yml 中添加日志级别环境变量配置 - 在 deploy.sh 的 .env 模板中添加日志级别配置说明 - 支持通过环境变量动态配置日志级别,无需修改配置文件 - 默认值:root=INFO, app=DEBUG --- .../polymarketbot/service/accounts/PositionCheckService.kt | 2 +- .../polymarketbot/service/common/MarketPriceService.kt | 4 ++-- backend/src/main/resources/application.properties | 6 +++--- deploy.sh | 5 +++++ docker-compose.prod.yml | 4 ++++ docker-compose.yml | 4 ++++ 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt index 4cfff21..ee25e64 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt @@ -398,7 +398,7 @@ class PositionCheckService( } else { // 有仓位,按订单下单顺序(FIFO)更新状态 // 计算逻辑: - // 1. 总订单数量 = 所有未卖出订单的剩余数量总和 + // 1. 总订单数量 = 所有未卖出订单的剩余数量总和 // 2. 已成交数量 = 总订单数量 - 仓位数量(因为还有仓位,说明部分订单已卖出) // 3. 如果已成交数量 = 0,说明订单还没有卖出,不修改订单状态 // 4. 如果已成交数量 > 0,按FIFO顺序匹配订单 diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/common/MarketPriceService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/common/MarketPriceService.kt index c9df632..ef620fc 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/common/MarketPriceService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/common/MarketPriceService.kt @@ -119,7 +119,7 @@ class MarketPriceService( if (isRpcError) { logger.warn("链上查询市场条件出现 RPC 错误(execution reverted),可能市场不存在或尚未创建: marketId=$marketId, error=${e.message}") } else { - logger.debug("链上查询市场条件失败,降级到 API 查询: marketId=$marketId, error=${e.message}") + logger.debug("链上查询市场条件失败,降级到 API 查询: marketId=$marketId, error=${e.message}") } Pair(null, isRpcError) } @@ -129,7 +129,7 @@ class MarketPriceService( if (isRpcError) { logger.warn("链上查询市场条件异常(execution reverted): marketId=$marketId, outcomeIndex=$outcomeIndex, error=${e.message}") } else { - logger.debug("链上查询市场条件异常: marketId=$marketId, outcomeIndex=$outcomeIndex, error=${e.message}") + logger.debug("链上查询市场条件异常: marketId=$marketId, outcomeIndex=$outcomeIndex, error=${e.message}") } Pair(null, isRpcError) } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index ef73a28..68f0b3a 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -29,9 +29,9 @@ server.port=${SERVER_PORT:8000} # 默认使用 dev 环境,可通过 --spring.profiles.active=prod 切换 spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} -# 日志配置 -logging.level.root=INFO -logging.level.com.wrbug.polyhermes=DEBUG +# 日志配置(支持通过环境变量配置) +logging.level.root=${LOG_LEVEL_ROOT:INFO} +logging.level.com.wrbug.polymarketbot=${LOG_LEVEL_APP:DEBUG} logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %msg%n # Polymarket API 配置 diff --git a/deploy.sh b/deploy.sh index 3191b1e..d622803 100755 --- a/deploy.sh +++ b/deploy.sh @@ -76,6 +76,11 @@ JWT_SECRET=${JWT_SECRET} # 管理员密码重置密钥(已自动生成随机值,生产环境建议修改) ADMIN_RESET_PASSWORD_KEY=${ADMIN_RESET_KEY} + +# 日志级别配置(可选,默认值:root=INFO, app=DEBUG) +# 可选值:TRACE, DEBUG, INFO, WARN, ERROR, OFF +# LOG_LEVEL_ROOT=INFO +# LOG_LEVEL_APP=DEBUG EOF info ".env 文件已创建,已自动生成随机密码和密钥" warn "生产环境建议修改以下参数:" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 6ecb88c..12d1765 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -29,6 +29,10 @@ services: # 生成随机密钥:openssl rand -hex 32 (ADMIN_RESET_PASSWORD_KEY) 或 openssl rand -hex 64 (JWT_SECRET) - JWT_SECRET=${JWT_SECRET:-change-me-in-production} - ADMIN_RESET_PASSWORD_KEY=${ADMIN_RESET_PASSWORD_KEY:-change-me-in-production} + # 日志级别配置(可选,默认值:root=INFO, app=DEBUG) + # 可选值:TRACE, DEBUG, INFO, WARN, ERROR, OFF + - LOG_LEVEL_ROOT=${LOG_LEVEL_ROOT:-INFO} + - LOG_LEVEL_APP=${LOG_LEVEL_APP:-DEBUG} depends_on: mysql: condition: service_healthy diff --git a/docker-compose.yml b/docker-compose.yml index d7f94c8..c1efeb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,10 @@ services: # 生成随机密钥:openssl rand -hex 32 (ADMIN_RESET_PASSWORD_KEY) 或 openssl rand -hex 64 (JWT_SECRET) - JWT_SECRET=${JWT_SECRET:-change-me-in-production} - ADMIN_RESET_PASSWORD_KEY=${ADMIN_RESET_PASSWORD_KEY:-change-me-in-production} + # 日志级别配置(可选,默认值:root=INFO, app=DEBUG) + # 可选值:TRACE, DEBUG, INFO, WARN, ERROR, OFF + - LOG_LEVEL_ROOT=${LOG_LEVEL_ROOT:-INFO} + - LOG_LEVEL_APP=${LOG_LEVEL_APP:-DEBUG} depends_on: mysql: condition: service_healthy