Skip to content

Commit

Permalink
Output start messages together with failed ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarst committed Aug 18, 2015
1 parent 8a56aef commit ee34a7e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions error-extract.py
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime


def pretty_print(message):
def pretty_print(message, separator=True):
"""
Print human-readable messages to stdout.
"""
Expand All @@ -24,28 +24,45 @@ def add_field(previous, key, value):
remaining += add_field(remaining, key, value)

level = "/" + "/".join(map(str, message["task_level"]))
output = "%s%s %sZ\n%s\n" % (
output = "%s%s %sZ\n%s" % (
message["task_uuid"],
level,
datetime.utcfromtimestamp(message["timestamp"]).time().isoformat(),
remaining,
)
if not sys.stdout.isatty():
output = output.encode("utf-8")
if separator:
output += "\n"
sys.stdout.write(output)


def main():
cached_start_messages = {}

for line in sys.stdin:
try:
message = json.loads(line)
except ValueError:
# Stupid systemd/journald corrupted the log message
continue
if (message.get("message_type") == "eliot:traceback" or
(message.get("action_type") and
message["action_status"] == "failed")):
if message.get("message_type") == "eliot:traceback":
pretty_print(message)
elif message.get("action_type"):
action_type = message["action_type"]
task_uuid = message["task_uuid"]
task_level = tuple(message["task_level"][:-1])
status = message["action_status"]
key = (action_type, task_uuid, task_level)
if status == "started":
cached_start_messages[key] = message
else:
try:
start_message = cached_start_messages.pop(key)
except KeyError:
start_message = None
if status == "failed":
if start_message:
pretty_print(start_message, separator=False)
pretty_print(message)


main()
Expand Down

0 comments on commit ee34a7e

Please sign in to comment.