management:
endpoints:
web:
exposure:
include:"*"
endpoint:
health:
show-details:ALWAYS
logfile:
external-file: logs/${spring.application.name}.log
logging:
level:
root:info
pattern:
file:"%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"
file:
path: logs/${spring.application.name}.log# path和name设置一个即可,name的优先级高
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">
<contextName>logback
<property name="log.path" value="logs" />
<property name="log.name" value="hn-cloud-gateway" />
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %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}}" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
<appender name="LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/${log.name}.log
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
<charset>UTF-8
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/${log.name}.%d{yyyy-MM-dd}.log
<maxHistory>1
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/${log.name}-error.log
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/${log.name}-error.%d{yyyy-MM-dd}.log
<maxHistory>1
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR
<onMatch>ACCEPT
<onMismatch>DENY
<springProfile name="dev">
<root level="debug">
<appender-ref ref="CONSOLE" />
<appender-ref ref="LOG_FILE" />
<appender-ref ref="ERROR_FILE" />
<!-- 4.2 生产环境:输出到文档 -->
<springProfile name="prod">
<root level="info">
<appender-ref ref="LOG_FILE" />
<appender-ref ref="ERROR_FILE" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<logger name="jdbc.sqlonly" level="OFF">
<logger name="jdbc.audit" level="INFO">
<logger name="jdbc.resultset" level="OFF">
<logger name="jdbc.connection" level="OFF">
<logger name="jdbc.sqltiming" level="OFF">
<appender-ref ref="CONSOLE" />
<logger name="org.springframework.web.servlet" level="info" />
<logger name="org.springframework.data.mongodb.core" level="DEBUG"/>