Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fastapi) Initialize JsonLogFormatter to pass to handler #107

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading