From 2126115df4cc8e3a51e6ecd69c46b1646747e985 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Wed, 26 Aug 2020 11:32:58 +0300 Subject: [PATCH] Send the last 1MB of error log as a file. --- setup-scripts/log-checker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup-scripts/log-checker.py b/setup-scripts/log-checker.py index 971ec3e8..bfb53895 100755 --- a/setup-scripts/log-checker.py +++ b/setup-scripts/log-checker.py @@ -77,13 +77,20 @@ async def check_docker_logs(): std_out, std_err = proc.communicate() if len(std_err) > 0: + # Trim the error log to under 1MB. + one_mb = 1024*1024 + if len(std_err) > one_mb: + pos = std_err.find("\n", -one_mb) + std_err = std_err[pos+1:] + upload_name = "{}-{}-{}-{}-{}:{}:{}_err.log".format(container_name, time.year, time.month, time.day, time.hour, time.minute, time.second) + await send_msg(client, "Error(s) found in log!", file=discord.File(io.BytesIO(std_err.encode()), filename=upload_name), force_notify=True) # Send at most 1900 characters of logs, rounded down to the nearest new line. # This is a limitation in the size of Discord messages - they can be at most # 2000 characters long (and we send some extra characters before the error log). if len(std_err) > 1900: pos = std_err.find("\n", -1900) std_err = std_err[pos+1:] - await send_msg(client, "Error(s) found in log:\n{}".format(std_err), force_notify=True) + await send_msg(client, "Error(s) preview:\n{}".format(std_err), force_notify=True) return # If there are any critical errors. upload the whole log file.