Logback日志文件配置模板


<configuration debug="true" scan="true" scanPeriod="30 secondes">

    <property name="CONSOLE_APPENDER_NAME" value="CONSOLE"/>
    <property name="FILE_APPENDER_NAME" value="FILE"/>
    <property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSSS} - [Thread-%thread] -[level-%-5level] - [%class : %method : %line] -  %msg %n"/>
    <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSSS} - [Thread:%thread] - [level: %-5level] - [%class : %method : %line] - %msg %n"/>
    <property name="FILE_NAME_PATTERN" value="%d{yyyy-MM-dd}.%i.log"/>
    <property name="FILE_PATH" value="D:/Log/Test-Client-Log.log"/>
    <property name="ROOT_LEVEL" value="debug"/>

    <appender name="${CONSOLE_APPENDER_NAME}" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${CONSOLE_LOG_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    <appender name="${FILE_APPENDER_NAME}" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${FILE_PATH}-${FILE_NAME_PATTERN}FileNamePattern>
            <MaxHistory>30MaxHistory>
            <maxFileSize>2MBmaxFileSize>
            <totalSizeCap>10MBtotalSizeCap>
        rollingPolicy>
        <encoder>
            <pattern>${FILE_LOG_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    <root level="${ROOT_LEVEVL}">
        <appender-ref ref="${CONSOLE_APPENDER_NAME}"/>
        <appender-ref ref="${FILE_APPENDER_NAME}"/>
    root>

    <logger name="com.apache.ibatis" level="TRACE"/>
    <logger name="java.sql.Connection" level="DEBUG"/>
    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
    <logger name="java.sql.Statement" level="DEBUG"/>
configuration>

标签集中集中配置所有的自定义的变量,方便管理;具体的标签的意思请参考- 解释

你可能感兴趣的:(Speing,cloud)