Skip to content

Commit ea3d2ba

Browse files
authored
(fastapi) Initialize JsonLogFormatter to pass to handler (#107)
1 parent 540563a commit ea3d2ba

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/dockerflow/fastapi/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
logger.setLevel(logging.INFO)
6060
handler = logging.StreamHandler(sys.stdout)
6161
handler.setLevel(logging.INFO)
62-
handler.setFormatter(JsonLogFormatter)
62+
handler.setFormatter(JsonLogFormatter())
6363
logger.addHandler(handler)
6464
self.logger = logger
6565

tests/fastapi/test_fastapi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,21 @@ def test_lbheartbeat_head(client):
4747
assert response.content == b""
4848

4949

50-
def test_mozlog(app, client, caplog):
50+
def test_mozlog_record_formatted_as_json(app, client, capsys):
51+
app.state.DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True
52+
53+
client.get(
54+
"/__lbheartbeat__?x=شكر",
55+
headers={
56+
"User-Agent": "dockerflow/tests",
57+
"Accept-Language": "en-US",
58+
},
59+
)
60+
stdout = capsys.readouterr().out
61+
assert json.loads(stdout)
62+
63+
64+
def test_mozlog_record_attrs(app, client, caplog):
5165
app.state.DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True
5266

5367
client.get(

0 commit comments

Comments
 (0)