如何在Logback中过滤stacktrace帧 [英] How to filter stacktrace frames in Logback

查看:432
本文介绍了如何在Logback中过滤stacktrace帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个Java类:foo.ClassAbar.ClassB.要打印(根)异常stacktrace,我只需要打印foo包的框架.我的问题是我究竟可以如何配置Logback来做到这一点.
我知道该功能已经在Logback中实现,因此我需要使用evaluator.但是我无法弄清楚.我尝试在此处中描述的示例未成功(不足为奇).

Say I have two Java classes: foo.ClassA and bar.ClassB. To print (root) exception stacktrace, I need to print only frames of foo package. My question is how exactly I can configure Logback to do that.
I know that the feature is already implemented in Logback, and I need to use evaluator. But I couldn't figure it out. I tried the example described here without success (no surprise).

任何人都可以给出用于过滤堆栈跟踪帧的确切配置吗?

Can anyone give the exact configuration for filtering stacktrace frames?

<configuration>
  <evaluator name="FILTER">
    <expression>¿what should I put here?</expression>
  </evaluator>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder>
      <pattern>[%thread] %-5level - %msg%n%rEx{full, FILTER}</pattern>
    </encoder>
  </appender>

  <root level="DEBUG"> 
    <appender-ref ref="STDOUT" /> 
  </root>
</configuration>

推荐答案

我联系了Tomasz Nurkiewicz(该问题中链接的博客的作者),他很高兴回答了我的问题.我发布答案,以防万一:
打印堆栈跟踪时,要过滤bar包中的行,请使用以下命令:

I contacted Tomasz Nurkiewicz (the author of the blog linked in the question) and he kindly answered my question. I'm posting the answer, just in case:
While printing stack trace, to filter lines from bar package use the following:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder>
      <pattern>[%thread] %-5level - %msg%n%rEx{full, bar}</pattern>
    </encoder>
  </appender>
  ...
</configuration>

我想在我的Web应用程序(Tomcat + Spring + Hibernate + etc)中使用它.因此,我使用以下命令配置了logback,以不打印org.something软件包中的任何堆栈跟踪行(例如,org.apacheorg.springframeworkorg.hibernate等):

I wanted to use it in my web application (Tomcat+Spring+Hibernate+etc). So I configured logback with the following not to print any stack trace line from org.something packages (e.g. org.apache, org.springframework, org.hibernate, etc):

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder>
      <pattern>[%thread] %-5level - %msg%n%rEx{full, org}</pattern>
    </encoder>
  </appender>
  ...
</configuration>

感谢托马斯!

这篇关于如何在Logback中过滤stacktrace帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆