springboot整合logback日志

springboot整合logback日志

  • logback maven 配置
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-classicartifactId>
        dependency>
  • logback日志配置,日志级别,日志文件产生测量,控制台输入策略


<configuration>

    <property name="LOG_PATH" value="${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}" />
    
    
    <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">
        
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}pattern>
            <charset>utf-8charset>
        encoder>
        
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>infolevel>
        filter>
    appender>


    
    <appender name="FILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_PATH}/boot-%d{yyyy-MM-dd}.log
            FileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%npattern>
        encoder>
        
        <triggeringPolicy
            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MBMaxFileSize>
        triggeringPolicy>
    appender>

    
    <root level="debug">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    root>
configuration>

boot yml配置

server:
  port: 80
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=utf8&useSSL=false
    maxActive: 20 
    initialSize: 3
    maxWait: 60000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000 
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true 
    maxOpenPreparedStatements: 20
    maxPoolPreparedStatementPerConnectionSize: 20
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
    filters: stat,wall
  output:
    ansi:
      enabled: detect
mybatis:
    mapperLocations: classpath*:com/boot/mapper/xml/*Mapper.xml
    typeAliasesPackage: com.boot.entity
logging:
  path: D:/日志/

如果想在eclipse 下的console输入彩色日志,需要下载eclipse下的插件 ansi
启动项目即可。

你可能感兴趣的:(spring-boot)