加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

logback.xml 单独配置class 日志级别并且显示类名和行数

发布时间:2020-12-16 02:16:40 所属栏目:百科 来源:网络整理
导读:1、对某个包下面的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 messag

1、对某个包下面的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.

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

View as .groovy

<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可以单独配置日志运行的级别。

2、配置日志打印行数和类名

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  <encoder>
   <pattern>%date-%level-[%F:%L]-[%thread]-%msg%n</pattern> ##F 类名 L 行数
  </encoder>
</appender>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读