Skip to content

Commit

Permalink
(fastapi) Initialize JsonLogFormatter to pass to handler (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamalama committed Apr 5, 2024
1 parent 540563a commit ea3d2ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dockerflow/fastapi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
handler.setFormatter(JsonLogFormatter)
handler.setFormatter(JsonLogFormatter())
logger.addHandler(handler)
self.logger = logger

Expand Down
16 changes: 15 additions & 1 deletion tests/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ def test_lbheartbeat_head(client):
assert response.content == b""


def test_mozlog(app, client, caplog):
def test_mozlog_record_formatted_as_json(app, client, capsys):
app.state.DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True

client.get(
"/__lbheartbeat__?x=شكر",
headers={
"User-Agent": "dockerflow/tests",
"Accept-Language": "en-US",
},
)
stdout = capsys.readouterr().out
assert json.loads(stdout)


def test_mozlog_record_attrs(app, client, caplog):
app.state.DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True

client.get(
Expand Down

0 comments on commit ea3d2ba

Please sign in to comment.