<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2018 PHOENIXFIN PTE. LTD.
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<!-- 打印IP -->
<conversionRule conversionWord="ip" converterClass="com.kucoin.starter.log.IPLogConfig" />
<!-- 打印hostname -->
<conversionRule conversionWord="hostname" converterClass="com.kucoin.starter.log.HostNameLogConfig" />
<!-- 全局配置userId -->
<turboFilter class="com.kucoin.starter.chaincontext.log.UserIdLogbackFilter" />
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<springProperty scope="context" name="logLevel" source="logging.level" defaultValue="INFO" />
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs" />
<property name="COMMON_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%thread] %c{32} [${springAppName},%hostname,%ip,%X{X-UserId:-},%X{trace_id:-},%X{span_id:-}] %m%n"/>
<!-- [公共Appender] 控制台STDOUT -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="CONSOLE-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="CONSOLE"/>
</appender>
<!-- Appender to log to file -->
<appender name="DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-default.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-default.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="DEFAULT-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="DEFAULT-APPENDER"/>
</appender>
<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-error.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="ERROR-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="ERROR-APPENDER"/>
</appender>
<appender name="BIZ-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-biz.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-biz.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="BIZ-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="BIZ-APPENDER"/>
</appender>
<appender name="REQUEST-LOG-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/requests.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/requests.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>1GB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>{"appName":"${springAppName}","hostname":"%hostname","traceId":"%X{trace_id:-}","request":%m}%n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="REQUEST-LOG-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="REQUEST-LOG-APPENDER"/>
</appender>
<springProfile name="prod">
<logger name="com.kucoin" level="${logLevel}" additivity="false">
<appender-ref ref="BIZ-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</logger>
<logger name="request-log" level="INFO" additivity="false">
<appender-ref ref="REQUEST-LOG-APPENDER-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="DEFAULT-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</root>
</springProfile>
<springProfile name="!prod">
<logger name="com.kucoin" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="CONSOLE-ASYNC"/>
</root>
</springProfile>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2018 PHOENIXFIN PTE. LTD.
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<!-- 打印IP -->
<conversionRule conversionWord="ip" converterClass="com.kucoin.starter.log.IPLogConfig" />
<!-- 打印hostname -->
<conversionRule conversionWord="hostname" converterClass="com.kucoin.starter.log.HostNameLogConfig" />
<!-- 全局配置userId -->
<turboFilter class="com.kucoin.starter.chaincontext.log.UserIdLogbackFilter" />
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<springProperty scope="context" name="logLevel" source="logging.level" defaultValue="INFO" />
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs" />
<property name="COMMON_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%thread] %c{32} [${springAppName},%hostname,%ip,%X{X-UserId:-},%X{trace_id:-},%X{span_id:-}] %m%n"/>
<!-- [公共Appender] 控制台STDOUT -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="CONSOLE-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="CONSOLE"/>
</appender>
<!-- Appender to log to file -->
<appender name="DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>{logPath}/common-default.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="DEFAULT-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="DEFAULT-APPENDER"/>
</appender>
<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>{logPath}/common-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="ERROR-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="ERROR-APPENDER"/>
</appender>
<appender name="BIZ-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>{logPath}/common-biz.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<!-- 每个文件最大100M,保留30天历史记录,但所有文件总大小不超过20G -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="BIZ-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="BIZ-APPENDER"/>
</appender>
<appender name="REQUEST-LOG-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>{logPath}/requests.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>1GB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>{"appName":"${springAppName}","hostname":"%hostname","traceId":"%X{trace_id:-}","request":%m}%n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="REQUEST-LOG-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="REQUEST-LOG-APPENDER"/>
</appender>
<springProfile name="prod">
<logger name="com.kucoin" level="${logLevel}" additivity="false">
<appender-ref ref="BIZ-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</logger>
<logger name="request-log" level="INFO" additivity="false">
<appender-ref ref="REQUEST-LOG-APPENDER-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="DEFAULT-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</root>
</springProfile>
<springProfile name="!prod">
<logger name="com.kucoin" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="CONSOLE-ASYNC"/>
</root>
</springProfile>
</configuration>
The provided XML configuration file is for setting up Logback, a logging framework for Java applications. This configuration is designed specifically for a project associated with PHOENIXFIN PTE. LTD. and handles various logging requirements, including logging to the console and different files based on the log level and environment (prod or non-prod).
Here's a breakdown of the key components and their purposes:
<conversionRule conversionWord="ip" converterClass="com.kucoin.starter.log.IPLogConfig" />
<conversionRule conversionWord="hostname" converterClass="com.kucoin.starter.log.HostNameLogConfig" />
These rules define custom conversion words to log IP addresses and hostnames using the specified converter classes.<turboFilter class="com.kucoin.starter.chaincontext.log.UserIdLogbackFilter" />
This filter adds a global user ID to the logs.<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<springProperty scope="context" name="logLevel" source="logging.level" defaultValue="INFO" />
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs" />
These placeholders are used to fetch properties from the Spring context.<property name="COMMON_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%thread] %c{32} [${springAppName},%hostname,%ip,%X{X-UserId:-},%X{trace_id:-},%X{span_id:-}] %m%n"/>
This pattern defines the format for log entries, including timestamp, log level, thread, logger name, application name, hostname, IP address, user ID, trace ID, span ID, and the log message.Console Appender:
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
Logs messages to the console.
Async Console Appender:
<appender name="CONSOLE-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="CONSOLE"/>
</appender>
Asynchronous version of the console appender.
Default File Appender:
<appender name="DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-default.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-default.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
Logs messages to a file, with rolling policies based on size and time.
Async Default File Appender:
<appender name="DEFAULT-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="DEFAULT-APPENDER"/>
</appender>
Error File Appender:
<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-error.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
Business File Appender:
<appender name="BIZ-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-biz.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-biz.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
Request Log Appender:
<appender name="REQUEST-LOG-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/requests.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/requests.log.%d{yyyy-MM-dd
这个XML配置文件是用于设置Logback的,它是一个用于Java应用程序的日志记录框架。该配置文件特别适用于PHOENIXFIN PTE. LTD.相关的项目,并处理各种日志记录需求,包括根据日志级别和环境(生产或非生产)记录到控制台和不同的文件。
以下是关键组件及其用途的详细说明:
<conversionRule conversionWord="ip" converterClass="com.kucoin.starter.log.IPLogConfig" />
<conversionRule conversionWord="hostname" converterClass="com.kucoin.starter.log.HostNameLogConfig" />
这些规则定义了自定义转换词,以使用指定的转换器类记录IP地址和主机名。<turboFilter class="com.kucoin.starter.chaincontext.log.UserIdLogbackFilter" />
这个过滤器会在日志中添加全局用户ID。<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<springProperty scope="context" name="logLevel" source="logging.level" defaultValue="INFO" />
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs" />
这些占位符用于从Spring上下文中获取属性。<property name="COMMON_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p [%thread] %c{32} [${springAppName},%hostname,%ip,%X{X-UserId:-},%X{trace_id:-},%X{span_id:-}] %m%n"/>
这个模式定义了日志条目的格式,包括时间戳、日志级别、线程、记录器名称、应用名称、主机名、IP地址、用户ID、跟踪ID、跨度ID和日志消息。控制台追加器:
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
将消息记录到控制台。
异步控制台追加器:
<appender name="CONSOLE-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="CONSOLE"/>
</appender>
控制台追加器的异步版本。
默认文件追加器:
<appender name="DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-default.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-default.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
将消息记录到文件,并根据大小和时间进行滚动。
异步默认文件追加器:
<appender name="DEFAULT-APPENDER-ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>64</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="DEFAULT-APPENDER"/>
</appender>
错误文件追加器:
<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-error.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
业务文件追加器:
<appender name="BIZ-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/common-biz.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/common-biz.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${COMMON_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
请求日志追加器:
<appender name="REQUEST-LOG-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/requests.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logPath}/requests.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>1GB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>{"appName":"${springAppName}","hostname":"%hostname","traceId":"%X{trace_id:-}","request":%m}%n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
生产环境:
<springProfile name="prod">
<logger name="com.kucoin" level="${logLevel}" additivity="false">
<appender-ref ref="BIZ-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</logger>
<logger name="request-log" level="INFO" additivity="false">
<appender-ref ref="REQUEST-LOG-APPENDER-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="DEFAULT-APPENDER-ASYNC"/>
<appender-ref ref="ERROR-APPENDER-ASYNC"/>
</root>
</springProfile>
非生产环境:
<springProfile name="!prod">
<logger name="com.kucoin" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE-ASYNC"/>
</logger>
<root level="${logLevel}">
<appender-ref ref="CONSOLE-ASYNC"/>
</root>
</springProfile>
这个配置文件根据不同环境(生产或非生产)设置了不同的日志输出方式,并定义了多个追加器用于控制台和文件的日志记录。