Skip to content

Commit

Permalink
Add exception command (#6)
Browse files Browse the repository at this point in the history
* Add exception command

* Fix lint

---------

Co-authored-by: Augusto Vanderley <[email protected]>
  • Loading branch information
augustovanderley and augustovanderleyneoway authored Oct 19, 2023
1 parent 3f66eb8 commit b8c774d
Show file tree
Hide file tree
Showing 2 changed files with 21 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
18 changes: 18 additions & 0 deletions test_lodge.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,21 @@ 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:
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 b8c774d

Please sign in to comment.