Monday, March 2, 2015

Logback config to suppress event by stacktrace element

Log event in file:
[2015-03-02 09:03:14,418] [server] [user] [ajp-bio-8009-exec-33] [Session][] [ERROR] - An exception has been thrown while processing following requests: '[Request[oid=2021,name=updateSelection,args=[ [ [ 2, 3 ], [ 6, 6 ], [ 11, 11 ] ] ]], Request[oid=2019,name=handleEvent,args=[ popupBeforeOpen, beforePopupOpen, [  ] ]]]'.
java.lang.NullPointerException: null
at com.company.View.fillContextMenu(View.java:444) 
at com.company.View.access$500(View.java:107)
at com.company.View$2.beforePopupOpen(View.java:303)
at sun.reflect.GeneratedMethodAccessor791.invoke(Unknown Source) ~[na:na]


to suppress that event following logback configuration for ch.qos.logback.classic.boolex.JaninoEventEvaluator is required:
<included>

   <property name="common.log.date.format" value="{MM/dd HH:mm:ss:SSS}" />
   <property name="common.log.conversionpattern" value="[%d${common.log.date.format}] [%X{username}] [%c{0}] [%marker] [%p]: %m%n" />

   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
      <target>System.out</target>
      <encoder>
         <pattern>${common.log.conversionpattern}</pattern>
      </encoder>
<!-- perform more precise filtering, you can suppress particular messages here -->
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression><![CDATA[
// suppress ERRORs from legacy code
if (level == ERROR
&& logger.contains("Session")
&& message.contains("handleEvent,args=[ popupBeforeOpen, beforePopupOpen, [  ] ]")
&& message.contains("updateSelection")
       && message.contains("An exception has been thrown while processing following requests")
        && throwableProxy != null && "java.lang.NullPointerException".equals(throwableProxy.getClassName())
&& throwableProxy.getStackTraceElementProxyArray()[0].getSTEAsString().contains("com.mycompany.View.fillContextMenu")
) {
return false;
}

return true;
]]></expression>
</evaluator>
<OnMatch>NEUTRAL</OnMatch>
<OnMismatch>DENY</OnMismatch>
</filter>
   </appender>

   <root level="INFO">
      <appender-ref ref="STDOUT" />
   </root>

</included>

No comments:

Post a Comment