Skip to content

Commit 3110c1d

Browse files
committed
Format log records early
1 parent a14b3a1 commit 3110c1d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/conftest.py

+34
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,40 @@
153153
asyncio.set_event_loop_policy = lambda policy: None
154154

155155

156+
class HackLogRecord(logging.LogRecord):
157+
"""Hack."""
158+
159+
def __init__(
160+
self,
161+
name,
162+
level,
163+
pathname,
164+
lineno,
165+
msg,
166+
args,
167+
exc_info,
168+
func=None,
169+
sinfo=None,
170+
**kwargs,
171+
) -> None:
172+
"""Initialize the log record."""
173+
super().__init__(
174+
name, level, pathname, lineno, msg, args, exc_info, func, sinfo, **kwargs
175+
)
176+
msg = str(self.msg)
177+
if self.args:
178+
msg = msg % self.args
179+
self.msg = msg
180+
self.args = None
181+
182+
def getMessage(self):
183+
"""Return the message for this LogRecord."""
184+
return self.msg
185+
186+
187+
logging.setLogRecordFactory(HackLogRecord)
188+
189+
156190
def pytest_addoption(parser: pytest.Parser) -> None:
157191
"""Register custom pytest options."""
158192
parser.addoption("--dburl", action="store", default="sqlite://")

0 commit comments

Comments
 (0)