xml logback的配置模板

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml logback的配置模板相关的知识,希望对你有一定的参考价值。

<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
  
  <!-- Simple file output -->
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- rollover daily -->
      <fileNamePattern>logs/template-server-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy
          class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 64 MB -->
        <maxFileSize>64 MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>

    <!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
    <prudent>true</prudent>
  </appender>


  <!-- Console output -->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
    <encoder>
      <pattern>%-5level %logger{36} - %msg%n</pattern>
    </encoder>
    <!-- Only log level INFO and above -->
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>WARN</level>
    </filter>
  </appender>


  <!-- Enable FILE and STDOUT appenders for all log messages.
       By default, only log at level INFO and above. -->
  <root level="INFO">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>

  <!-- For loggers in the these namespaces, log at all levels. -->
  <logger name="user" level="ALL" />
  <!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
  <logger name="pedestal" level="ALL" />
  -->

</configuration>

以上是关于xml logback的配置模板的主要内容,如果未能解决你的问题,请参考以下文章

LogBack.xml 配置模板

logback自定义Pattern模板

logback.xml引入外部配置文件

logback.xml常用配置

logback配置文件详解

logback.xml配置的日志文件在哪