Skip to content

Commit

Permalink
Do not repeat old messages & errors on new log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
oh2fih committed Jul 17, 2024
1 parent 5761a96 commit 7eb6086
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions json_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ def log(
target: str = None, message: str = None, error: Exception = None, obj: dict = {}
):
obj.update({"time": time.time()})

if target is not None and message is not None:
obj.update({"target": target, "message": str(message)})
elif target is not None:
obj.update({"message": str(target)})

if error is not None:
obj.update({"error": str(error)})
obj.update({"target": str(target), "message": str(message)})
obj.update({"error": str(error)})

print(
json.dumps(obj, default=str), file=sys.stdout if error is None else sys.stderr
Expand Down

0 comments on commit 7eb6086

Please sign in to comment.