From 2a461c808553bd161c558fedcbd00f70c57d47a5 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 28 Oct 2021 22:06:48 +0800 Subject: Change arguments to AdminLog.log Several keys of a monolithic dict are now discrete args --- jimbrella/admin_log.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py index e30809e..d1c57c2 100644 --- a/jimbrella/admin_log.py +++ b/jimbrella/admin_log.py @@ -80,16 +80,21 @@ class AdminLog: f.close() return logs - def log(self, entry: dict) -> None: - """Serialize a log, and append it to the end of the log file.""" - # wait until database is locked for this write - while not self.lockfile.lock(): - continue + def log(self, event: str, entry: dict, date=None, note="") -> None: + """Serialize a log, and append it to the end of the log file. + + Arguments: + event | one of the events defined in the class docstring. + entry | information pertaining to the log entry. + date | if is None, defaults to `datetime.now()`. + note | optional note. + """ + self.lockfile.lock() with open(self.path, "a") as f: # append only writer = csv.writer(f) - event = entry["event"] - line = [event, entry["date"].isoformat()] + date = date or datetime.now() + line = [event, date.isoformat()] info = [] if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"): info = [ @@ -115,7 +120,7 @@ class AdminLog: ] line.extend(info) - line.append(entry["note"]) + line.append(note) writer.writerow(line) f.close() -- cgit v1.2.3