logback.xml 單獨配置class 日誌級別而且顯示類名和行數

一、對某個包下面的class 單獨配置日誌級別-Example

Setting the level of a logger or root logger is as simple as declaring it and setting its level, as the next example illustrates. Suppose we are no longer interested in seeing any DEBUG messages from any component belonging to the "chapters.configuration" package. The following configuration file shows how to achieve that.app

Example: Setting the level of a logger (logback-examples/src/main/resources/chapters/configuration/sample2.xml)spa

View as .groovyrest

<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="chapters.configuration" level="INFO"/>

  <!-- Strictly speaking, the level attribute is not necessary since -->
  <!-- the level of the root level is set to DEBUG by default.       -->
  <root level="DEBUG">          
    <appender-ref ref="STDOUT" />
  </root>  
  
</configuration>

logback.xml能夠單獨配置日誌運行的級別。日誌

二、配置日誌打印行數和類名code

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%date-%level-[%F:%L]-[%thread]-%msg%n</pattern> ##F 類名 L 行數
    </encoder>
</appender>
相關文章
相關標籤/搜索