• spring boot日志配置


    spring boot的application.properties提供了日志的配置,但我还是习惯于老的logback的使用方式。以下内容介绍如何在springboot中使用自定义的logback。

    1、在src/main/resources目录下创建logback.xml文件,内容如下:

    <!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
    <configuration scan="true" scanPeriod="10 seconds">
        <include resource="org/springframework/boot/logging/logback/base.xml" />
    
        <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <File>${LOG_PATH}/info.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i
                </fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>500MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
                <maxHistory>2</maxHistory>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
                </Pattern>
            </layout>
        </appender>
    
        <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>ERROR</level>
            </filter>
            <File>${LOG_PATH}/error.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
                </fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>500MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
                <maxHistory>2</maxHistory>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
    
                </Pattern>
            </layout>
        </appender>
        
        <!-- hibernate日志输入 -->
        <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
            level="TRACE" />
        <logger name="org.hibernate.type.descriptor.sql.BasicExtractor"
            level="TRACE" />
        <logger name="org.hibernate.SQL" level="DEBUG" />
        <logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
        <logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
    
        <root level="INFO">
            <appender-ref ref="INFO_FILE" />
            <appender-ref ref="ERROR_FILE" />
        </root>
        
    </configuration>

    2、在application.properties中指定logback.xml和日志生成的路径,如下:

    logging.config=classpath:logback.xml
    logging.path=/workspace/rock/jpa-test/log
  • 相关阅读:
    L99
    L98
    L97
    PyQt(Python+Qt)学习随笔:model/view架构中的QStandardItemModel使用案例
    PyQt(Python+Qt)学习随笔:model/view架构中的两个标准模型QStandardItemModel和QFileSystemModel
    PyQt(Python+Qt)学习随笔:Model/View架构中的Model模型概念
    PyQt(Python+Qt)学习随笔:Model/View架构概述
    第十四章、Model/View开发:Model/View架构程序设计模式
    Python中数字按位取反的方法
    PyQt(Python+Qt)学习随笔:Model中项的标记flags取值及枚举类型Qt.ItemFlag
  • 原文地址:https://www.cnblogs.com/puroc/p/5049222.html
Copyright © 2020-2023  润新知