-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mark Laing <[email protected]>
- Loading branch information
1 parent
86d9a32
commit 4b56433
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import re | ||
|
||
# Looks for a panic by grepping for stacktraces in a log file. | ||
# If a panic is found, it exits with code 1 and prints the stacktrace plus the last log message. | ||
# Only the first panic is returned. | ||
# If no panics are found it exits with code 0 | ||
with open(sys.argv[1]) as file: | ||
output = "" | ||
lastline = "" | ||
for line in file: | ||
if output == "" and not re.search("^goroutine\s+\d+\s+\[running]:", line): | ||
# Output empty and no regex match so nothing found yet. | ||
lastline = line | ||
continue | ||
|
||
if lastline != "": | ||
# Got a regex match on this line, start the output with the last line and set it empty. | ||
output = lastline + line | ||
lastline = "" | ||
continue | ||
|
||
if re.search("(INFO|DEBUG|TRACE|WARNING|ERROR)", line): | ||
# Print the stack trace and exit when we encounter the next standard log message | ||
sys.stdout.write(output) | ||
exit(1) | ||
else: | ||
# While we don't have standard log messages, append the output (the stacktrace). | ||
output += line | ||
|
||
exit(0) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters