• springboot配置logback的使用


    logback.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <property name="LOG_HOME" value="/logs/mama-bike"/>
            <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
              <encoder>
                 <pattern>%d{H:mm} %-5level [%logger{16}] %msg%n</pattern>
              </encoder>
           </appender>
    
            <appender name="normalLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${LOG_HOME}/web.normal.%d{yyyy-MM-dd}.log</fileNamePattern>
                    <MaxHistory>30</MaxHistory>
                </rollingPolicy>
                <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                    <maxFileSize>10MB</maxFileSize>
                </triggeringPolicy>
                <layout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{16} - %msg%n</pattern>
                </layout>
                <filter class="ch.qos.logback.classic.filter.LevelFilter">
                    <level>ERROR</level>
                    <onMatch>DENY</onMatch>
                    <onMismatch>ACCEPT</onMismatch>
                </filter>
            </appender>
    
            <appender name="errorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${LOG_HOME}/web.error.%d{yyyy-MM-dd}.log</fileNamePattern>
                    <MaxHistory>30</MaxHistory>
                </rollingPolicy>
                <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                    <maxFileSize>10MB</maxFileSize>
                </triggeringPolicy>
                <layout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{16} - %msg%n</pattern>
                </layout>
                <filter class="ch.qos.logback.classic.filter.LevelFilter">
                    <level>ERROR</level>
                    <onMatch>ACCEPT</onMatch>
                    <onMismatch>DENY</onMismatch>
                </filter>
            </appender>
    
            <logger name="com.coder520.mamabike" level="debug">
                <appender-ref ref="normalLog" />
                <appender-ref ref="errorLog" />
            </logger>
    
           <root level="info">
              <appender-ref ref="Console" />
           </root>
    </configuration>

    引入的包:

    <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>1.1.6</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.1.6</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-access</artifactId>
                <version>1.1.2</version>
            </dependency>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.2</version>
            </dependency>
  • 相关阅读:
    粤语·简约学习笔记
    Linux的网卡由eth0变成了eth1
    RedHat 更新CentOS Yum源
    Lamp 搭建
    像淘宝、京东这样的大型电商网站服务器构架完全部署方案
    完成静态服务器——Node.js摸石头系列之四
    实现使用Websocket通讯的聊天室——Node.js摸石头系列之六
    Node.js摸石头系列目录
    Aptana studio 3 修改配色方案
    Node.js 的安装和控制台命令——Node.js摸石头系列之一
  • 原文地址:https://www.cnblogs.com/fuckingPangzi/p/9967577.html
Copyright © 2020-2023  润新知