首页 > 代码库 > spring boot 默认的 logback

spring boot 默认的 logback

1、在resource目录下写logback.xml 文件

2、

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<jmxConfigurator/>
<!-- ROLLINGFILE 满足一定大小后重新生成文件-->
<appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
      <fileNamePattern>log-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<!--文件最多保留的天数-->
       <maxHistory>1</maxHistory>
       <!--文件最大为多少-->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<encoder>
       <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
   <!-- show parameters for hibernate sql 专为 Hibernate 定制 -->
   <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
   <logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
   <logger name="org.hibernate.SQL" level="DEBUG" /> <logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
   <logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
  
  <!--myibatis log configure 位mybatis制作-->
   <logger name="com.apache.ibatis" level="TRACE"/>
   <logger name="java.sql.Connection" level="DEBUG"/>
   <logger name="java.sql.Statement" level="DEBUG"/>
   <logger name="java.sql.PreparedStatement" level="DEBUG"/>
   <!-- 日志输出级别 -->

<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ROLLINGFILE"/>
</root>
  <!--日志异步到数据库 -->
  <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
            <!--日志异步到数据库 -->
     <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
               <!--连接池 -->
      <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
         <driverClass>com.mysql.jdbc.Driver</driverClass>
        <url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
         <user>root</user>
         <password>root</password>
      </dataSource>
     </connectionSource>
  </appender>

</configuration>

spring boot 默认的 logback