lnav
lnav copied to clipboard
Filtering entries with Java exceptions
Hi,
I tried and failed to filter log entries with exceptions. I want to include entries that contain an Exception followed by a stack trace, but I want to not include entries that merely contain the word "exception".
Test log:
10:24:31.826 [⋮] DEBUG c - an IllegalStateException has been thrown: should be excluded
10:24:31.826 [⋮] DEBUG c - an exception has been thrown:
java.lang.IllegalStateException: A book has a null property
at com.example.myproject.Author.getBookIds(Author.java:38)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
10:24:31.826 [⋮] DEBUG c - another exception has been thrown: java.lang.IllegalStateException: A book has a null property
at com.example.myproject.Author.getBookIds(Author.java:38)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
Last attempt:
lnav -n -c ':filter-in (?:Exception|Error).*(\v\s+at.*)+' test.log
Unfortunately, this matches nothing.
Any help would be highly appreciated!
Using lnav 0.8.5
Currently, the filtering regex is tested against each line and not the full log message. So, the second half of the regex (i.e. (\v\s+at.*)+) won't match anything.
I am thinking of changing around lnav's guts to work on full messages instead of individual lines. So, I think this issue will be fixed by those changes.
Cool, this would be highly appreciated, as exceptions / stack traces are inherently multi-line.
I've recently pushed changes to allow filtering using a SQL expression (see #568). The SQL expression has access to the full message, so I think you can accomplish what you want by doing something like:
:log_body regexp '(?:Exception|Error).*(\v\s+at.*)+'
You'll need to build from the top-of-tree for this to work.
Just tested it on my machine. Nice feature! Looking forward to see this in the next release!