From 961a64106a570db50d28d46b81a3c4e5af1abeb5 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期一, 16 十二月 2024 16:10:58 +0800
Subject: [PATCH] 1、data和model模块修改logback-spring.xml日志配置 2、gateway增加server.servlet.context-path: /

---
 iailab-module-data/iailab-module-data-biz/src/main/resources/logback-spring.xml |  140 +++++++++++++++++++++-------------------------
 1 files changed, 65 insertions(+), 75 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/resources/logback-spring.xml b/iailab-module-data/iailab-module-data-biz/src/main/resources/logback-spring.xml
index 3ac202f..db8f353 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/resources/logback-spring.xml
+++ b/iailab-module-data/iailab-module-data-biz/src/main/resources/logback-spring.xml
@@ -1,86 +1,76 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration scan="true">
-    <property name="LOG_TEMP" value="./logs"/>
+<configuration>
+    <!-- 引用 Spring Boot 的 logback 基础配置 -->
     <include resource="org/springframework/boot/logging/logback/defaults.xml" />
-    <!-- <include resource="org/springframework/boot/logging/logback/base.xml" /> -->
-    <logger name="org.springframework.web" level="INFO"/>
-    <logger name="org.springboot.sample" level="TRACE" />
+    <!-- 变量 iailab.info.base-package,基础业务包 -->
+    <springProperty scope="context" name="iailab.info.base-package" source="iailab.info.base-package"/>
+    <!-- 格式化输出:%d 表示日期,%X{tid} SkWalking 链路追踪编号,%thread 表示线程名,%-5level:级别从左显示 5 个字符宽度,%msg:日志消息,%n是换行符 -->
+    <property name="PATTERN_DEFAULT" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} | %highlight(${LOG_LEVEL_PATTERN:-%5p} ${PID:- }) | %boldYellow(%thread [%tid]) %boldGreen(%-40.40logger{39}) | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
 
-    <!-- 开发、测试环境 -->
-    <springProfile name="dev,test,prod">
-        <logger name="org.springframework.web" level="INFO"/>
-        <logger name="org.springboot.sample" level="INFO" />
-        <logger name="com.iailab" level="DEBUG" />
-    </springProfile>
-
-    <!-- 生产环境 -->
-    <!--<springProfile name="prod">-->
-    <!--<logger name="org.springframework.web" level="ERROR"/>-->
-    <!--<logger name="org.springboot.sample" level="ERROR" />-->
-    <!--<logger name="io.renren" level="ERROR" />-->
-    <!--</springProfile>-->
-
-    <!-- 日志文件存放路径 -->
-    <property name="log_home" value="./logs" />
-    <!-- 日志输出格式 -->
-    <!--生产用-->
-    <property name="log.pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] | [%thread][%-5level] | [%logger{20}.%method,line : %line] %msg%n" />
-    <!--本地测试使用-->
-    <!--<property name="log.pattern" value="[%boldGreen(%d{yyyy-MM-dd HH:mm:ss.SSS})] | [%highlight(%thread][%-5level)] | [%boldYellow(%logger{20}.%method,%line)] %msg%n" />-->
-    <!-- 日志输出格式【控制台】 -->
-    <!--<property name="log.pattern" value="%date{yyyy-MM-dd HH:mm:ss} | [ line: %line ] | %boldGreen(%thread) | %highlight(%-5level) | %boldYellow(%logger).%method | %msg%n"/>-->
-
-    <!-- 控制台输出 -->
-    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
-        <encoder>
-            <!--<pattern>${logPatternConsoleLog}</pattern>-->
-            <pattern>${log.pattern}</pattern>
+    <!-- 控制台 Appender -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">     
+        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
+                <pattern>${PATTERN_DEFAULT}</pattern>
+            </layout>
         </encoder>
     </appender>
 
-    <logger name="m-shop-mybatis-sql" level="debug"></logger>
-
-    <!-- debug级别设置 -->
-    <appender name="file_debug"  class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <prudent>true</prudent>
-        <filter class="ch.qos.logback.classic.filter.LevelFilter">
-            <!--过滤 DEBUG-->
-            <level>DEBUG</level>
-            <!--匹配到就禁止-->
-            <!--<onMatch>ACCEPT</onMatch>-->
-            <!--没有匹配到就允许-->
-            <!--<onMismatch>DENY</onMismatch>-->
-        </filter>
-        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <!--<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">-->
-            <!--日志文件输出的文件名-->
-            <!--<FileNamePattern>${log_home}/log-info.%d{yyyy-MM-dd}.%i.log</FileNamePattern>-->
-            <FileNamePattern>${log_home}/log-debug.%d{yyyy-MM-dd}.log</FileNamePattern>
-            <!--<maxFileSize>100MB</maxFileSize>-->
-            <!-- 日志最大的历史 7天 -->
-            <maxHistory>7</maxHistory>
-            <totalSizeCap>2GB</totalSizeCap>
-            <cleanHistoryOnStart>true</cleanHistoryOnStart>
+    <!-- 文件 Appender -->
+    <!-- 参考 Spring Boot 的 file-appender.xml 编写 -->
+    <appender name="FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
+                <pattern>${PATTERN_DEFAULT}</pattern>
+            </layout>
+        </encoder>
+        <!-- 日志文件名 -->
+        <file>${LOG_FILE}</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!-- 滚动后的日志文件名 -->
+            <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern>
+            <!-- 启动服务时,是否清理历史日志,一般不建议清理 -->
+            <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart>
+            <!-- 日志文件,到达多少容量,进行滚动 -->
+            <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}</maxFileSize>
+            <!-- 日志文件的总大小,0 表示不限制 -->
+            <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}</totalSizeCap>
+            <!-- 日志文件的保留天数 -->
+            <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}</maxHistory>
         </rollingPolicy>
-        <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">-->
-        <!--&lt;!&ndash; 单文件最大50MB &ndash;&gt;-->
-        <!--<maxFileSize>50MB</maxFileSize>-->
-        <!--</triggeringPolicy>-->
-        <encoder>
-            <pattern>${log.pattern}</pattern>
+    </appender>
+    <!-- 异步写入日志,提升性能 -->
+    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
+        <!-- 不丢失日志。默认的,如果队列的 80% 已满,则会丢弃 TRACT、DEBUG、INFO 级别的日志 -->
+        <discardingThreshold>0</discardingThreshold>
+        <!-- 更改默认的队列的深度,该值会影响性能。默认值为 256 -->
+        <queueSize>256</queueSize>
+        <appender-ref ref="FILE"/>
+    </appender>
+
+    <!-- SkyWalking GRPC 日志收集,实现日志中心。注意:SkyWalking 8.4.0 版本开始支持 -->
+    <appender name="GRPC" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
+        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+            <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
+                <pattern>${PATTERN_DEFAULT}</pattern>
+            </layout>
         </encoder>
     </appender>
 
-    <!-- 系统模块日志级别控制  -->
-    <!--<logger name="com.btrh" level="info" />-->
-
-    <!-- Spring日志级别控制  -->
-    <!--<logger name="org.springframework" level="info" />-->
-
-    <!--系统操作日志-->
-    <root level="INFO">
-        <appender-ref ref="console" />
-        <appender-ref ref="file_debug" />
-    </root>
+    <!-- 本地环境 -->
+    <springProfile name="local">
+        <root level="INFO">
+            <appender-ref ref="STDOUT"/>
+            <appender-ref ref="GRPC"/> <!-- 本地环境下,如果不想接入 SkyWalking 日志服务,可以注释掉本行 -->
+            <appender-ref ref="ASYNC"/>  <!-- 本地环境下,如果不想打印日志,可以注释掉本行 -->
+        </root>
+    </springProfile>
+    <!-- 其它环境 -->
+    <springProfile name="dev,test,stage,prod,default">
+        <root level="INFO">
+            <appender-ref ref="STDOUT"/>
+            <appender-ref ref="ASYNC"/>
+            <appender-ref ref="GRPC"/>
+        </root>
+    </springProfile>
 
 </configuration>

--
Gitblit v1.9.3