How to filter/remove specific logging messages in JBoss EAP 6/7 ?

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Issue

  • How to remove specific logging message from log file
  • How can we filter out an undesirable message from our logs? We have a warning message that occurs very frequently and is cluttering up the file.
  • We need to prevent a certain log message, from showing up in the logs
  • How can we remove certain logs statements from our logs?
  • In EAP 5 we defined appenders with custom filters, to suppress specific log entries. What is the equivalent in EAP 6/7?
  • We would like to mute certain exception messages in our logs, how can we do this?
  • In domain mode, unable to add a log filter with a double quote. When deployed in Linux server, the domain could not start while using:
/profile=full-ha/subsystem=logging/periodic-size-rotating-file-handler=FILE/:write-attribute(name=filter-spec,value= "not(match("IJ000604"))")
  • Replacing Logback with JBoss logging leads to difference between the log formats
  • How to filter out specific logging message from server.log in EAP 7
  • How to use filter-spec attribute ?
  • How to filter out specific logging message from server.log in EAP 7 using CLI
  • How to configure logging filter in EAP6
  • I'd like to configure logging filter in EAP 6.2.0. I used the following filter in older EAP6, but it does not work in EAP 6.2.0 any longer.
  <logger category="org.jboss.security">
    <level name="WARN"/>
    <filter>
      <not>
        <match pattern="PBOX000206.*"/>
      </not>
    </filter>
  </logger>

Resolution

Be aware that it is not possible to use a filter-spec based on logger name i.e org.jboss.as.server.deployment.

To exclude the stdout or an entire category refers to Suppressing entire log statements from "stdout", "stderr" or specific log category in JBoss EAP 6.x/7.x.

EAP 6.0.x

In EAP 6.0.x, there is a new syntax used with the logging manager that looks like this. Declare it inside the handler definition inside the logging subsystem in standalone.xml or domain.xml. For example:

<filter>
    <not>
       <match pattern="Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003"/>
    </not>
 </filter>

The <not> tag is equivalent to AcceptOnMatch=false in EAP 5.x, omitting the <not> is equivalent to AcceptOnMatch=true.

It can be set by the following command in CLI:

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter,value={"not"=>{"match"=>"Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003"}})
/subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name=filter,value={"not"=>{"match"=>"Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003"}})
Note: For domain mode, prepend /profile=profilename (e.g. /profile=full).

EAP 6.1.1+/7.x

In EAP 6.1.1 onwards, filter expressions are introduced, use <filter-spec> instead of <filter> inside the logging subsystem in standalone.xml or domain.xml.

Note: For further information about Filter Expressions, refers to Logging Configuration - Filter Expressions documentation.

Examples

To include messages that do not match a set of message codes:

CLI:

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec,value=not(match("Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003")))
/subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name=filter-spec,value=not(match("Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003")))

XML:

<filter-spec value="not(match(&quot;Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003&quot;))"/>
To include messages that do match a set of message codes:

CLI:

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec,value=match("Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003"))

XML:

<filter-spec value="match(&quot;Set SEI name after eager initialization|JBAS000000|JBAS000001|JBAS000002|JBAS000003&quot;)"/>
To include messages that do match a set of message codes prefix:

CLI:

/subsystem=logging/periodic-rotating-file-handler=hqFILE:write-attribute(name=filter-spec,value=match("HHH.*"))

XML:

<filter-spec value="match(&quot;HHH.*&quot;)"/>
To remove log entries containing specific strings. For example:
Remove [java:jboss/datasources from the CONSOLE logs:
16:33:12,258 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]

CLI:

 /subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec,value=not(match("\\[java:jboss/datasources"))
Remove log entries containing strings Deployed, deploy, EAP 6.2.0, [java:jboss/mail, [java:jboss/datasources/ExampleDS]:

CLI:

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec,value=not(match("JBAS018210|Deployed|deployment|EAP 6.2.0|\\[java:jboss/mail|\\[java:jboss/datasources/ExampleDS]"))

Caveat:
The CPU cost of evaluating regular expressions with filter-spec is high, and there is a possibility that performance will degrade the performance of JBoss EAP depending on the amount of logging.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.