I do a lot of grepping through logs generated by Java’s Log4j and Python’s logging module. Both create stack traces that include newline characters, causing the log entry to span multiple lines. This makes things hard to find with grep and violates the conventional log file formatting rules (one entry per line).
If I find something interesting in the stack trace, I have to open entire the log file (which can be very large) and browse to the line grep found, then scroll up to find the start of the log entry. This feels kludgey.
Is there a better way to handle this? Perhaps removing newline characters from stack traces somehow?
Thanks for any suggestions!
If you have GNU grep you can use the
-C(AKA--context) switch:I’m not sure if
-Cis part of POSIX grep but it is worth a shot.