-
-
Notifications
You must be signed in to change notification settings - Fork 726
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
Set propagate
to False
on "uvicorn" logger
#1288
Conversation
this seems to break quite a lots of our tests @guyskk |
@euri10 I see, will check on it. |
Hi @euri10, the failures is because pytest caplog not able to capture And the caplog_for_logger helper also not work on test config cases, because when create Config object, A simple work around is set |
mm this is where I'm not too sure, I remeber that pytest issue and I think the fixture was written just for that, and if you look at the way we use it, we do Config first then only we use the fixture so I dont think that explanation is correct, but I may be off |
Yes, the caplog_for_logger works when test logs after create Config object, but it can not capture logs inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with some tweaks in the explanation and a rebase that solves conflicts it's ready to be merged for me
It does. Changed the milestone. The milestones are mainly so I can organize myself. It's a self promise that I'm going to look for the current milestone before the release. :) |
# The simple solution is set propagate=True before execute tests. | ||
# | ||
# See also: https://github.com/pytest-dev/pytest/issues/3697 | ||
LOGGING_CONFIG["loggers"]["uvicorn"]["propagate"] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then... all our users needs to do this if capturing the logs on their setup, right? 🤔
Should we mention this somewhere, or it's fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all our users needs to do this if capturing the logs on their setup, right?
I think if users want to config uvicorn's logs, they should provide full logging config, no needs to set propagate. https://www.uvicorn.org/settings/#logging
And if users only want to config application logs, call logging.basicConfig
works as expected, uvicorn's logs will not affected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if people want to capture those logs on their test, for some reason (?) they need to do the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then... all our users needs to do this if capturing the logs on their setup, right? thinking
Should we mention this somewhere, or it's fine?
It introduces a change only for the users who in their tests, use a Config object and are looking for logs if I get it correctly, logging is complex so I'll admit I'm not 100% sure.
I'd be tempted to say it's a rather slim part of people in that case but I may be proven wrong, but there's no harm in saying something like:
Should you use the caplog pytest fixture in your test suite to capture uvicorn logs, you might want to use (the line above) if you use a Config object, please see (test line that explains it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts on this @guyskk ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I just wanted to point this out, I don't have any strong opinion about this, jfyk)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if people want to capture those logs on their test, for some reason (?) they need to do the same thing.
Yes. Maybe mention it in changelog? if those user's tests broken(rare usage), they can easily know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let's add a note then !
@@ -119,7 +119,7 @@ | |||
}, | |||
}, | |||
"loggers": { | |||
"uvicorn": {"handlers": ["default"], "level": "INFO"}, | |||
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False}, | |||
"uvicorn.error": {"level": "INFO"}, | |||
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guyskk Is this "propagate": False
still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is.
propagate
to False
on "uvicorn" logger
Fix #1285