From 69556c047aa3bc64dc7e305de32d4f3c60d1a171 Mon Sep 17 00:00:00 2001 From: zhangjf Date: Sun, 22 Feb 2026 21:14:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8INSTANCE=5FNAME=E5=8C=BA=E5=88=86=E5=A4=9A?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:多实例部署时,APP_NAME相同导致日志互相覆盖 - 实例1: fund-sys (普通租户) - 实例2: fund-sys-vip (VIP租户) - 日志都写入 /datacfs/applogs/fund-sys/ ❌ 修改: - start.sh: - 添加 -Dapp.instance.name=${INSTANCE_NAME} 参数 - 日志目录改为 ${LOG_HOME}/${INSTANCE_NAME} - logback-spring.xml (9个服务): - APP_NAME source改为 app.instance.name - 默认值保持服务名用于fallback 效果: - 实例1: /datacfs/applogs/fund-sys/info.log - 实例2: /datacfs/applogs/fund-sys-vip/info.log ✅ --- fund-cust/src/main/resources/logback-spring.xml | 5 +++-- fund-exp/src/main/resources/logback-spring.xml | 5 +++-- fund-file/src/main/resources/logback-spring.xml | 5 +++-- fund-gateway/src/main/resources/logback-spring.xml | 5 +++-- fund-proj/src/main/resources/logback-spring.xml | 5 +++-- fund-receipt/src/main/resources/logback-spring.xml | 5 +++-- fund-report/src/main/resources/logback-spring.xml | 5 +++-- fund-req/src/main/resources/logback-spring.xml | 5 +++-- fund-sys/src/main/resources/logback-spring.xml | 5 +++-- scripts/start.sh | 9 +++++---- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/fund-cust/src/main/resources/logback-spring.xml b/fund-cust/src/main/resources/logback-spring.xml index 475822e..05c9048 100644 --- a/fund-cust/src/main/resources/logback-spring.xml +++ b/fund-cust/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-exp/src/main/resources/logback-spring.xml b/fund-exp/src/main/resources/logback-spring.xml index 375be32..adccffa 100644 --- a/fund-exp/src/main/resources/logback-spring.xml +++ b/fund-exp/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-file/src/main/resources/logback-spring.xml b/fund-file/src/main/resources/logback-spring.xml index c439ff9..5ee087f 100644 --- a/fund-file/src/main/resources/logback-spring.xml +++ b/fund-file/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-gateway/src/main/resources/logback-spring.xml b/fund-gateway/src/main/resources/logback-spring.xml index 77ef818..acf0b31 100644 --- a/fund-gateway/src/main/resources/logback-spring.xml +++ b/fund-gateway/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-proj/src/main/resources/logback-spring.xml b/fund-proj/src/main/resources/logback-spring.xml index a8abb2c..cc6306c 100644 --- a/fund-proj/src/main/resources/logback-spring.xml +++ b/fund-proj/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-receipt/src/main/resources/logback-spring.xml b/fund-receipt/src/main/resources/logback-spring.xml index 76e7288..081b86c 100644 --- a/fund-receipt/src/main/resources/logback-spring.xml +++ b/fund-receipt/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-report/src/main/resources/logback-spring.xml b/fund-report/src/main/resources/logback-spring.xml index 4af285e..50711c5 100644 --- a/fund-report/src/main/resources/logback-spring.xml +++ b/fund-report/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-req/src/main/resources/logback-spring.xml b/fund-req/src/main/resources/logback-spring.xml index abcb6b5..f2d0d13 100644 --- a/fund-req/src/main/resources/logback-spring.xml +++ b/fund-req/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/fund-sys/src/main/resources/logback-spring.xml b/fund-sys/src/main/resources/logback-spring.xml index 1bde0b7..c25d449 100644 --- a/fund-sys/src/main/resources/logback-spring.xml +++ b/fund-sys/src/main/resources/logback-spring.xml @@ -2,11 +2,12 @@ - + + - + diff --git a/scripts/start.sh b/scripts/start.sh index c0a8626..59aed62 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -59,8 +59,9 @@ PID_FILE="${APP_HOME}/${INSTANCE_NAME}.pid" # JVM参数(可通过环境变量覆盖) JAVA_OPTS="${JAVA_OPTS:--Xms256m -Xmx512m -XX:+UseG1GC -XX:MaxGCPauseMillis=200}" -# 日志目录参数(其他日志配置在application.yml/logback-spring.xml中) +# 日志目录参数(使用INSTANCE_NAME区分实例) LOG_OPTS="-Dlogging.file.path=${LOG_HOME}" +LOG_OPTS="$LOG_OPTS -Dapp.instance.name=${INSTANCE_NAME}" # 多租户参数 TENANT_OPTS="" @@ -77,8 +78,8 @@ if [ -f "$PID_FILE" ]; then fi fi -# 创建日志目录 -mkdir -p ${LOG_HOME} +# 创建日志目录(使用INSTANCE_NAME区分实例) +mkdir -p ${LOG_HOME}/${INSTANCE_NAME} # 启动服务 echo "Starting ${INSTANCE_NAME}..." @@ -94,7 +95,7 @@ if [ -n "${TENANT_ID}" ]; then fi # 启动命令:java -cp lib/*:conf MainClass -nohup java $JAVA_OPTS $LOG_OPTS $TENANT_OPTS -cp "$CLASSPATH" $MAIN_CLASS > /dev/null 2>&1 & +nohup java $JAVA_OPTS $LOG_OPTS $TENANT_OPTS -cp "$CLASSPATH" $MAIN_CLASS >${LOG_HOME}/${INSTANCE_NAME}/stdout.log 2>&1 & # 保存PID echo $! > $PID_FILE