Merge pull request #349 from NebulousLabs/fix-err-msg
Use a clearer log message and add some debug output.
This commit is contained in:
commit
c587cb0d38
|
@ -57,7 +57,9 @@ async def check_docker_logs():
|
|||
container_name = sys.argv[2]
|
||||
|
||||
# Get the container id for siad.
|
||||
stream = os.popen('docker ps -q --filter name=^{}$'.format(container_name))
|
||||
cmd = 'docker ps -q --filter name=^{}$'.format(container_name)
|
||||
print("[DEBUG] will run `{}`".format(cmd))
|
||||
stream = os.popen(cmd)
|
||||
image_id = stream.read().strip()
|
||||
|
||||
# Get the number of hours to look back in the logs or use 1 as default.
|
||||
|
@ -70,11 +72,25 @@ async def check_docker_logs():
|
|||
time_string = "{}h".format(check_hours)
|
||||
|
||||
# Read the logs.
|
||||
print("[DEBUG] Will run `docker logs --since {} {}`".format(time_string, image_id))
|
||||
proc = Popen(["docker", "logs", "--since", time_string, image_id], stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True)
|
||||
std_out, std_err = proc.communicate()
|
||||
|
||||
if len(std_err) > 0:
|
||||
await send_msg(client, "Error reading docker logs output: {}".format(std_err), force_notify=True)
|
||||
# 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) preview:\n{}".format(std_err), force_notify=True)
|
||||
return
|
||||
|
||||
# If there are any critical errors. upload the whole log file.
|
||||
|
|
Reference in New Issue