记录折腾的那点事
在折腾的道路上永不止步

logback-spring.xml文件有注解说明

logback-spring.xml文件有注解说明

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="defPath" value="logs/"/>
    <property name="defPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %5p [%c:%L] - %m%n"/>
    <property name="defRollingSize" value="100MB"/>
    <property name="defRollingMax" value="3"/>
    <logger name="com.gs" level="debug"/>
    <logger name="org.springframework.web" level="info"/>
    <logger name="org.ibatis" level="DEBUG"/>
    <logger name="druid.sql" level="DEBUG"/>
    <logger name="org.springframework.jdbc" level="WARN"/>
    <logger name="springfox.documentation" level="WARN"/>
    <logger name="com.netflix.discovery" level="WARN"/>
    <logger name="org.springframework.context" level="WARN"/>
    <logger name="org.springframework.core" level="WARN"/>
    <logger name="org.springframework.data" level="WARN"/>
    <!-- 控制台打印 -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${defPattern}</pattern>
        </encoder>
    </appender>
    <!--  记录系统核心运行环节的日志,包括错误信息 -->
    <appender name="dmsLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${defPath}/logs.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${defPath}/logs-%i.log.gz</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>${defRollingMax}</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>${defRollingSize}</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>${defPattern}</pattern>
        </encoder>
    </appender>
    <!-- 仅仅额外记录系统各个环节的错误信息 -->
    <appender name="dmsErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${defPath}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${defPath}/error-%i.log.gz</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>${defRollingMax}</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>${defRollingSize}</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>${defPattern}</pattern>
        </encoder>
    </appender>
    <!-- 仅仅记录系统启动环节的日志 -->
    <appender name="dmsStartLog" class="ch.qos.logback.core.FileAppender">
        <file>${defPath}/start.log</file>
        <encoder>
            <pattern>${defPattern}</pattern>
        </encoder>
    </appender>
    <!-- 仅仅记录系统停止环节的日志 -->
    <appender name="dmsStopLog" class="ch.qos.logback.core.FileAppender">
        <file>${defPath}/stop.log</file>
        <encoder>
            <pattern>${defPattern}</pattern>
        </encoder>
    </appender>
    <!-- 可配置一个特殊的自定义Logger,把所有错误日志额外输出到此文件,方便识别是否有错误发生 -->
    <!-- 理想健康的系统,此日志文件的大小应该为零。后续可根据此错误日志时间及内容,去主日志dms.log里头定位 -->
    <logger name="dms.logger.for.error.only" level="error" addtivity="false">
        <appender-ref ref="dmsErrorLog"/>
    </logger>
    <!-- 启动环节需要记录日志时使用此自定义logger -->
    <logger name="dms.logger.for.start.only" level="error" addtivity="false">
        <appender-ref ref="dmsStartLog"/>
    </logger>
    <!-- 停止环节需要记录日志时使用此自定义logger -->
    <logger name="dms.logger.for.stop.only" level="error" addtivity="false">
        <appender-ref ref="dmsStopLog"/>
    </logger>
    <root level="INFO">
        <appender-ref ref="console"/>
        <appender-ref ref="dmsLog"/>
        <appender-ref ref="dmsErrorLog"/>
        <appender-ref ref="dmsStartLog"/>
    </root>
</configuration>

赞(0)
未经允许不得转载:ghMa » logback-spring.xml文件有注解说明
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址