[英]Filtering Middleware Frames from Stack Trace Logs in JBoss 7 with Filter-spec
I want to reduce the length of my exception logging on JBoss 7 while losing as little valuable information as possible. 我想减少在JBoss 7上登录异常的时间,同时尽可能少地丢失有价值的信息。 What I am trying to do is to filter out any JBoss middleware stack frames which usual provide litle insight into actual issues in application code.
我正在尝试做的是过滤掉任何JBoss中间件堆栈框架,这些框架通常可以为应用程序代码中的实际问题提供一点洞察力。 Example of frames I am trying to filter: "at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)" or " at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)".
我尝试过滤的框架示例:“在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)”或“在org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)”。
I have been able filter out regular log entries completely using a filter-spec in the logging configuration in the JBoss configuration file: 我已经能够在JBoss配置文件的日志记录配置中使用filter-spec完全过滤掉常规日志条目:
<console-handler name="CONSOLE">
<level name="TRACE" />
<formatter>
<pattern-formatter
pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n" />
</formatter>
<filter-spec value="not(match("Validation"))" />
</console-handler>
I have also been able to replace log entries that match a particular filter expression: 我还能够替换与特定过滤器表达式匹配的日志条目:
<console-handler name="CONSOLE">
<level name="TRACE" />
<formatter>
<pattern-formatter
pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n" />
</formatter>
<filter-spec value="substituteAll("Validation", "Im here!!!!")" />
<filter-spec value="not(match("Validation"))" />
</console-handler>
But when I try to substitute an exception stacktrace frame instead of a regular log entry it does not work. 但是,当我尝试用异常堆栈跟踪框架代替常规日志条目时,它不起作用。 the filter-spec I am trying to use is:
我尝试使用的过滤器规格是:
<filter-spec value="substituteAll("sun.reflect.NativeMethodAccessorImpl", "")" />
But this filter seems to ignore stack traces. 但是此过滤器似乎忽略了堆栈跟踪。
Can anyone suggest a way to filter these stack traces in a JBoss environment? 谁能在JBoss环境中建议一种过滤这些堆栈跟踪的方法?
Unfortunately filters don't work on exceptions. 不幸的是,过滤器不适用于异常。 Also currently there's no ability to use custom filters either.
另外,目前也无法使用自定义过滤器。 You can however either use a
custom-formatter
or custom-handler
which could do that for your. 但是,您可以使用
custom-formatter
或custom-handler
来为您执行此操作。
An example custom handler could look something like: 示例自定义处理程序可能类似于:
public class TrimCauseHandler extends Handler {
private Handler delegate;
@Override
public synchronized void publish(final LogRecord record) {
if (delegate != null) {
final Throwable cause = record.getThrown();
if (cause != null) {
final Collection<StackTraceElement> st = new ArrayList<>();
for (StackTraceElement e : cause.getStackTrace()) {
final String className = e.getClassName();
if (className.startsWith("org.jboss.as") || className.startsWith("org.wildfly")) {
continue;
}
st.add(e);
}
cause.setStackTrace(st.toArray(new StackTraceElement[0]));
}
record.setThrown(cause);
delegate.publish(record);
}
}
@Override
public synchronized void flush() {
if (delegate != null) {
delegate.flush();
}
}
@Override
public synchronized void close() throws SecurityException {
if (delegate != null) {
delegate.close();
}
}
public synchronized Handler getDelegate() {
return delegate;
}
public synchronized void setDelegate(final Handler delegate) {
this.delegate = delegate;
}
}
Then a CLI command to use it for the console handler would be something like: 然后,将CLI命令用于控制台处理程序的命令将类似于:
/subsystem=logging/custom-handler=test:add(module=your.module, class=org.jboss.example.handlers.TrimCauseHandler, properties={delegate="CONSOLE"})
/subsystem=logging/root-logger=ROOT:remove-handler(name=CONSOLE)
/subsystem=logging/root-logger=ROOT:add-handler(name=test)
It doesn't look like arrays are supported property types so you'd have to wrap each handler in a TrimCauseHandler
or do something odd like make setDelegate()
add the handler to a collection of some sort. 看起来数组不是受支持的属性类型,因此您必须将每个处理程序包装在
TrimCauseHandler
或者做一些奇怪的事情,例如make setDelegate()
将处理程序添加到某种类型的集合中。
I just want to point out there is now an open JIRA to allow for custom filters. 我只想指出,现在有一个开放的JIRA允许自定义过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.