lnav icon indicating copy to clipboard operation
lnav copied to clipboard

Filtering entries with Java exceptions

Open matthiasS-da opened this issue 6 years ago • 6 comments

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!

matthiasS-da avatar Sep 16 '19 07:09 matthiasS-da

Using lnav 0.8.5

matthiasS-da avatar Sep 16 '19 07:09 matthiasS-da

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.

tstack avatar Sep 16 '19 08:09 tstack

Cool, this would be highly appreciated, as exceptions / stack traces are inherently multi-line.

matthiasS-da avatar Sep 16 '19 10:09 matthiasS-da

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.

tstack avatar Dec 07 '20 23:12 tstack

Just tested it on my machine. Nice feature! Looking forward to see this in the next release!

matthiasS-da avatar Feb 16 '21 15:02 matthiasS-da