Even more logging fixes #757

Merged
telackey merged 2 commits from telackey/morelog into main 2024-02-22 01:24:45 +00:00

View File

@ -40,13 +40,18 @@ class AttrDict(dict):
def logged_cmd(log_file, *vargs): def logged_cmd(log_file, *vargs):
result = None
try: try:
print(" ".join(vargs), file=log_file) if log_file:
result = subprocess.run(vargs, capture_output=True, stdout=log_file, stderr=log_file) print(" ".join(vargs), file=log_file)
result = subprocess.run(vargs, capture_output=True)
result.check_returncode() result.check_returncode()
return result.stdout.decode() return result.stdout.decode()
except Exception as err: except Exception as err:
print(str(err), file=log_file) if result:
print(result.stderr.decode(), file=log_file)
else:
print(str(err), file=log_file)
raise err raise err
@ -184,7 +189,7 @@ class LaconicRegistryClient:
self.set_name(name, new_record_id) self.set_name(name, new_record_id)
return new_record_id return new_record_id
finally: finally:
logged_cmd("rm", "-rf", tmpdir) logged_cmd(self.log_file, "rm", "-rf", tmpdir)
def set_name(self, name, record_id): def set_name(self, name, record_id):
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "set", name, record_id) logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)