I want to extract relevant data of an http thread which has been started with a specific UUID from a log file. Example log:
2018-09-26 06:34:24,815 INFO [com.xxx.xxx.xxx] (http-threads-threads - 73244) UUID: 111-222-333-444-555
2018-09-26 06:34:25,224 WARN [com.xxx.xxx.xxx] (http-threads-threads - 74391) Some log message
2018-09-26 06:34:26,782 INFO [com.xxx.xxx.xxx] (http-threads-threads - 74399) Some log message
2018-09-26 06:34:26,945 ERROR [com.xxx.xxx.xxx] (http-threads-threads - 73244) Some exception message of the right thread
at com.xxx.xxx.xxx(someclass.java:114) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:65) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:85) [classes:]
2018-09-26 06:34:26,950 ERROR [com.xxx.xxx.xxx] (http-threads-threads - 74256) Unauthorized: com.xxx.xxx.xxx: Unauthorized
at com.xxx.xxx.xxx(someclass.java:39) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:49) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:45) [somejar.jar:1.0.0]
2018-09-26 06:34:26,952 INFO [com.xxx.xxx.xxx] (http-threads-threads - 74395) Some log message
2018-09-26 06:34:27,014 WARN [com.xxx.xxx.xxx] (http-threads-threads - 73244) Some log message of the right thread
2018-09-26 06:34:27,530 INFO [com.xxx.xxx.xxx] (http-threads-threads - 74365) Some log message
I can already search for the UUID and extract the thread number using grep and BASH_REMATCH. Knowing the thread number I can search for "http-threads-threads - 73244". Now I want to print all lines with that string and any eventual exception (lines with tabs) after these lines.
I want an output like this:
2018-09-26 06:34:24,815 INFO [com.xxx.xxx.xxx] (http-threads-threads - 73244) UUID: 111-222-333-444-555
2018-09-26 06:34:26,945 ERROR [com.xxx.xxx.xxx] (http-threads-threads - 73244) Some exception message of the right thread
at com.xxx.xxx.xxx(someclass.java:114) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:65) [somejar.jar:1.0.0]
at com.xxx.xxx.xxx(someclass.java:85) [classes:]
2018-09-26 06:34:27,014 WARN [com.xxx.xxx.xxx] (http-threads-threads - 73244) Some log message of the right thread
I can't use grep -A 3
because the amount of tabbed lines after the match is variable.
Using awk '/http\-threads\-threads \- 73244/{print $0; getline}/\tat/{print $0}' log.log
also prints other tabbed lines.
Using awk '/http\-threads\-threads \- 73244/{a=1;print}/(2[0-9][0-9][0-9]\-[0-1]\-[0-9])/{a=0}' log.log
doesn't print the tabbed lines at all.
A perfect solution would also get rid of the extra "grep" and "BASH_REMATCH" before and use the UUID, but I would be totally fine with a solution which takes the thread number as "input".
Does anyone have a solution for this?