Detailed explanation of the use of the LogBack logging framework

<?xml version="1.0" encoding="UTF-8"?>
<!--
scan: When this property is set to true, the configuration file will be reloaded if it is changed. The default value is true.
scanPeriod: Set the time interval for monitoring whether the configuration file is modified. If the time unit is not given, the default unit is milliseconds. When scan is true, this property takes effect. The default time interval is 1 minute.
debug: When this property is set to true, the internal log information of logback will be printed out, and the running status of logback will be viewed in real time. The default value is false.
-->
<configuration scan="false" scanPeriod="60 seconds" debug="false">
    <!-- Define the root directory of the log -->
    <property name="LOG_HOME" value="/app/log" / >
    <!-- Define the log file name-->
    <property name="appName" value="atguigu-springboot"></property>
    <!-- ch.qos.logback.core.ConsoleAppender means console output -- >
    <appender name="


%d represents the date and time,
%thread represents the thread name,
%-5level: the level displays 5 characters from the left. The width
%logger{50} represents the logger name with a maximum length of 50 characters, otherwise it is divided by periods. 
%msg: log message,
%n is a newline
        -->
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread] %-5level %logger{50} - %msg%n</pattern>
        </layout>
    </appender>


    <!-- Scroll the record file, first record the log to the specified file, when a certain condition is met , log to other file -->  
    <appender name="appLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- specify the name of the log file -->
        <file>${ LOG_HOME}/${appName}.log</file>
        <!

        TimeBasedRollingPolicy: The most commonly used rolling policy, it formulates a rolling policy according to time, which is responsible for both rolling and starting rolling.
        -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--
            The storage location and file name of the files generated during rolling%d{yyyy-MM-dd}: log by day Scroll 
            %i: When the file size exceeds maxFileSize, scroll the file according to i
            -->
            <fileNamePattern>${LOG_HOME}/${appName}-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
            <!-- 
            Optional node, controls the maximum number of archived files to keep, and deletes old files if the number exceeds. Assuming that the setting is rolled every day,
            and maxHistory is 365, only the files of the last 365 days will be saved, and the old files will be deleted. Note that when deleting old files,
            those directories created for archiving are also deleted.
            -->
            <MaxHistory>365</MaxHistory>

            When the log file exceeds the size specified by maxFileSize, the log file is scrolled according to the %i mentioned above. Note that the SizeBasedTriggeringPolicy configured here cannot realize the scrolling according to the file size, and the timeBasedFileNamingAndTriggeringPolicy must be configured
            -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos" .logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <!-- log output format: -->     
        <layout class="ch.qos.logback.classic. PatternLayout">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n</pattern >
        </layout>
    < /appender>


    <!-- 
    -- root and logger are in a parent-child relationship. If there is no special definition, the default is root. Any class will only correspond to one logger,     either a defined logger or a root. The key to the judgment is to find the logger and then judge the logger. appenders and levels.      -->




















    <root level="info">
        <appender-ref ref="stdout" />
        <appender-ref ref="appLogAppender" />
    </root>
</configuration> 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325807357&siteId=291194637