c-starter-server.1.0.0.RELEASE.source-code.logback-spring.xml Maven / Gradle / Ivy
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- 可在 application-xx.yml 文件中配置 logback.path 覆盖默认值 --> <springProperty scope="context" name="LOG_PATH" source="logback.path" defaultValue="./logs"/> <springProperty scope="context" name="initEnable" source="gc.starter.logger.enable" defaultValue="false"/> <!-- 设置控制台颜色 --> <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{${LOG_DATEFORMAT_PATTERN:-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} %L %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> <property name="FILE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-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} %L %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> <!-- 根据条件判断是否使用自定义日志过滤器 --> <if condition='p("initEnable").equals("true")'> <then> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${CONSOLE_LOG_PATTERN}</pattern> <charset>UTF-8</charset> </encoder> <!-- 自定义日志过滤器、结合WS进行日志推送 --> <filter class="com.gccloud.starter.core.log.CustomLogFilter"></filter> </appender> </then> <else> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${CONSOLE_LOG_PATTERN}</pattern> <charset>UTF-8</charset> </encoder> </appender> </else> </if> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 追加日志到原文件结尾 --> <Prudent>true</Prudent> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %method 方法名 %L 行数 %msg:日志消息,%n是换行符--> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{56}.%method:%L - %msg%n</pattern> <charset>utf-8</charset> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!--日志文件输出的文件名 每小时生成日志文件--> <FileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd_HH}(%i).log</FileNamePattern> <!--日志文件保留天数--> <MaxHistory>7</MaxHistory> <!-- 除按日志记录之外,还配置了日志文件不能超过10M(默认),若超过10M,日志文件会以索引0开始, --> <maxFileSize>10MB</maxFileSize> <!-- 日志文件大小和超过100MB会清空之前的 --> <totalSizeCap>100MB</totalSizeCap> </rollingPolicy> </appender> <!-- SpringBoot 默认的 --> <logger name="org.apache.catalina.startup.DigesterFactory" level="ERROR"/> <logger name="org.apache.catalina.util.LifecycleBase" level="ERROR"/> <logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN"/> <logger name="org.apache.sshd.common.util.SecurityUtils" level="WARN"/> <logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN"/> <logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="ERROR"/> <logger name="org.hibernate.validator.internal.util.Version" level="WARN"/> <!-- 开发、测试环境 --> <springProfile name="dev,test"> <logger name="org.springframework.web" level="INFO"></logger> <logger name="org.springboot.sample" level="INFO"></logger> <logger name="com.gccloud.starter" level="INFO"></logger> </springProfile> <!-- 生产环境 --> <springProfile name="prod"> <logger name="org.springframework.web" level="ERROR"></logger> <logger name="org.springboot.sample" level="ERROR"></logger> <logger name="com.gccloud.starter" level="ERROR"></logger> </springProfile> <root level="INFO"> <appender-ref ref="FILE"/> <appender-ref ref="CONSOLE"/> </root> </configuration>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy