Skip to content

Commit b8c774d

Browse files
Add exception command (#6)
* Add exception command * Fix lint --------- Co-authored-by: Augusto Vanderley <[email protected]>
1 parent 3f66eb8 commit b8c774d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lodge.py

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ def warn(self, msg, *args, **kwargs):
118118
def error(self, msg, *args, **kwargs):
119119
self._get_logger().error(msg, *args, **kwargs)
120120

121+
def exception(self, msg, *args, **kwargs):
122+
self._get_logger().exception(msg, *args, **kwargs)
123+
121124
def fatal(self, msg, *args, **kwargs):
122125
self._get_logger().fatal(msg, *args, **kwargs)
123126

test_lodge.py

+18
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,21 @@ def test_proxy_log_warn_with_level_error_should_not_log(stream, monkeypatch):
153153
log_entry = stream.read()
154154

155155
assert log_entry == ""
156+
157+
158+
def test_proxy_exception_method(stream):
159+
with import_lodge() as lodge:
160+
log = lodge.get_logger("test")
161+
try:
162+
1/0
163+
except ZeroDivisionError:
164+
log.exception("test_message")
165+
166+
log_entry = stream.read()
167+
json_entry = log_entry.split("\n")[0]
168+
log_structured = json.loads(json_entry)
169+
170+
assert log_structured["message"] == "test_message"
171+
assert log_structured["level"] == "ERROR"
172+
assert "Traceback (most recent call last)" in log_entry
173+
assert "ZeroDivisionError: division by zero" in log_entry

0 commit comments

Comments
 (0)