Skip to content

Commit

Permalink
Add exception command
Browse files Browse the repository at this point in the history
  • Loading branch information
augustovanderleyneoway committed Oct 19, 2023
1 parent 3f66eb8 commit fba2bcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lodge.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def warn(self, msg, *args, **kwargs):
def error(self, msg, *args, **kwargs):
self._get_logger().error(msg, *args, **kwargs)

def exception(self, msg, *args, **kwargs):
self._get_logger().exception(msg, *args, **kwargs)

def fatal(self, msg, *args, **kwargs):
self._get_logger().fatal(msg, *args, **kwargs)

Expand Down
17 changes: 17 additions & 0 deletions test_lodge.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,20 @@ def test_proxy_log_warn_with_level_error_should_not_log(stream, monkeypatch):
log_entry = stream.read()

assert log_entry == ""

def test_proxy_exception_method(stream):
with import_lodge() as lodge:
log = lodge.get_logger("test")
try:
1/0
except ZeroDivisionError as e:
log.exception("test_message")

log_entry = stream.read()
json_entry = log_entry.split("\n")[0]
log_structured = json.loads(json_entry)

assert log_structured["message"] == "test_message"
assert log_structured["level"] == "ERROR"
assert "Traceback (most recent call last)" in log_entry
assert "ZeroDivisionError: division by zero" in log_entry

0 comments on commit fba2bcd

Please sign in to comment.