Skip to content

Commit

Permalink
Improve error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-daniels committed Jan 7, 2015
1 parent b465871 commit 260d17b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions excepthook.py
Expand Up @@ -11,10 +11,12 @@ def uncaught_exception(exctype, value, tb):
delta = now - UtcDate.startup_utc_date
seconds = delta.total_seconds()
tr = os.linesep.join(traceback.format_tb(tb))
print(tr)
exception_only = ''.join(traceback.format_exception_only(exctype, value)).strip()
logged_msg = exception_only + os.linesep + str(now) + " UTC" + os.linesep + tr + os.linesep + os.linesep
print(logged_msg)
with open("errorLogs.txt", "a") as f:
f.write(str(now) + " UTC" + os.linesep + tr + os.linesep + os.linesep)
if seconds < 180 :
f.write(logged_msg)
if seconds < 180:
os._exit(4)
else:
os._exit(1)
Expand Down
7 changes: 4 additions & 3 deletions ws.py
Expand Up @@ -71,14 +71,15 @@ def restart_automatically(time_in_seconds):
delta = now - UtcDate.startup_utc_date
seconds = delta.total_seconds()
tr = traceback.format_exc()
print(tr)
exception_only = ''.join(traceback.format_exception_only(type(e), e)).strip()
logged_msg = str(now) + " UTC" + os.linesep + exception_only + os.linesep + tr + os.linesep + os.linesep
print(logged_msg)
with open("errorLogs.txt", "a") as f:
f.write(str(now) + " UTC" + os.linesep + tr + os.linesep + os.linesep)
f.write(logged_msg)
if seconds < 180:
os._exit(4)
ws = websocket.create_connection("ws://qa.sockets.stackexchange.com/")
ws.send("155-questions-active")
exception_only = ''.join(traceback.format_exception_only(type(e), e)).strip()
GlobalVars.charcoal_hq.send_message("Recovered from `" + exception_only + "`")

now = datetime.utcnow()
Expand Down

0 comments on commit 260d17b

Please sign in to comment.