Skip to content

Instantly share code, notes, and snippets.

@jsvd
Created August 22, 2019 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsvd/2ceed2eccf1c14f197ce791a302af838 to your computer and use it in GitHub Desktop.
Save jsvd/2ceed2eccf1c14f197ce791a302af838 to your computer and use it in GitHub Desktop.
how to filter out an multi line error message in log4j2 using RegexFilter
appender.console.type = Console
appender.console.name = plain_console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %m%n
appender.console.filter.no_json_error.type = RegexFilter
appender.console.filter.no_json_error.regex = (?s).*JSON parse error.*
appender.console.filter.no_json_error.onMatch = DENY
appender.console.filter.no_json_error.onMismatch = ACCEPT
@jsvd
Copy link
Author

jsvd commented Aug 22, 2019

note the (?s), a.k.a. as DOTALL:

Enables dotall mode.
In dotall mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators.

Dotall mode can also be enabled via the embedded flag expression (?s). (The s is a mnemonic for "single-line" mode, which is what this is called in Perl.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment