项目地址:https://gitee.com/springzb/admin-boot
如果觉得不错,给个 star
简介:
这是一个基础的企业级基础后端脚手架项目,主要由springboot为基础搭建,后期整合一些基础插件例如:redis、xxl-job、flowable、minioio、easyexcel、skyWalking、rabbitmq
配置文件均在 \admin-boot\src\main\resources 目录下
在resources目录下新建 log 文件夹,在此目录下新建 logback-spring-dev.xml 日志配置文件
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<springProperty scope="context" name="app_name" source="spring.application.name" />
<contextName>logbackcontextName>
<property name="logPath" value="logs/${app_name}" />
<property name="log.max.file.size" value="100MB"/>
<property name="log.max.history" value="60"/>
<property name="log.total.size" value="3GB"/>
<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} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<contextName>logbackcontextName>
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${CONSOLE_LOG_PATTERN}pattern>
layout>
appender>
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFOlevel>
<onMatch>ACCEPTonMatch>
<onMismatch>DENYonMismatch>
filter>
<File>${logPath}/log_info.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${logPath}/info/%d{yyyy-MM-dd}/log-info-%i.gzFileNamePattern>
<maxFileSize>${log.max.file.size}maxFileSize>
<maxHistory>${log.max.history}maxHistory>
<totalSizeCap>${log.total.size}totalSizeCap>
rollingPolicy>
<encoder>
<charset>UTF-8charset>
<pattern>${FILE_LOG_PATTERN}pattern>
encoder>
appender>
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARNlevel>
<onMatch>ACCEPTonMatch>
<onMismatch>DENYonMismatch>
filter>
<File>${logPath}/log_warn.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${logPath}/warn/%d{yyyy-MM-dd}/log-warn-%i.gzFileNamePattern>
<maxFileSize>${log.max.file.size}maxFileSize>
<maxHistory>${log.max.history}maxHistory>
<totalSizeCap>${log.total.size}totalSizeCap>
rollingPolicy>
<encoder>
<charset>UTF-8charset>
<pattern>${FILE_LOG_PATTERN}pattern>
encoder>
appender>
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERRORlevel>
<onMatch>ACCEPTonMatch>
<onMismatch>DENYonMismatch>
filter>
<File>${logPath}/log_error.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${logPath}/error/%d{yyyy-MM-dd}/log-error-%i.gzFileNamePattern>
<maxFileSize>${log.max.file.size}maxFileSize>
<maxHistory>${log.max.history}maxHistory>
<totalSizeCap>${log.total.size}totalSizeCap>
rollingPolicy>
<encoder>
<charset>UTF-8charset>
<pattern>${FILE_LOG_PATTERN}pattern>
encoder>
appender>
<appender name="INFO_FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold >0discardingThreshold>
<queueSize>1024queueSize>
<neverBlock>trueneverBlock>
<appender-ref ref="INFO_FILE"/>
appender>
<appender name="WARN_FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold >0discardingThreshold>
<queueSize>1024queueSize>
<neverBlock>trueneverBlock>
<appender-ref ref="WARN_FILE"/>
appender>
<appender name="ERROR_FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold >0discardingThreshold>
<queueSize>1024queueSize>
<neverBlock>trueneverBlock>
<appender-ref ref="ERROR_FILE"/>
appender>
<root level="INFO">
<appender-ref ref="consoleLog"/>
<appender-ref ref="INFO_FILE_ASYNC"/>
<appender-ref ref="WARN_FILE_ASYNC"/>
<appender-ref ref="ERROR_FILE_ASYNC"/>
root>
configuration>
配置文件均在 \admin-boot\src\main\resources 目录下
修改配置文件 application-dev.yml ,在配置中指定日志配置文件所在位置
application-dev.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://81.69.43.78:3306/admin-boot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
username: root
password: task,.123
# 指定日志配置文件位置
logging:
config: classpath:log/logback-spring-dev.xml
运行项目启动类 cn.mesmile.admin.AdminApplication
可以看到在项目根目录下,已经生成 日志文件