-
-
Notifications
You must be signed in to change notification settings - Fork 60
Using root logger + flask outside of flask request context throws RuntimeError #61
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
Comments
thanks for reporting this, i put in a quick fix on 1.2.9 |
I updated to 1.2.9 and am still seeing the error. I'm just typing this straight into the python shell: import logging
import json_logging
from flask import Flask
app = Flask("my_app")
logging.basicConfig()
json_logging.init_flask(enable_json=True)
json_logging.init_request_instrument(app)
json_logging.config_root_logger()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.info("logging initialized") Which results in:
|
my bad, fix it again with 1.2.10 |
Sweet, that now works. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've noticed that I get a
RuntimeError: Working outside of application context.
if I try to log anything after initializing Flask logs but don't yet have a flask request context.Replication code is here:
This appears to be a bug in
json_logging.util.get_correlation_id
expecting that "no request" should have aNone
value but it actually comes back as an "unbound" instance ofwerkzeug.local.LocalProxy
. This fails to match in the check forrequest is None
and results in a call toself.request_adapter.get_correlation_id_in_request_context
that triggers the exception. It appears that the unboundLocalProxy
resolves toFalse
so checking bothrequest is None or not bool(request)
would work around this issue for Flask. I just don't know how that fix would affect other frameworks.The text was updated successfully, but these errors were encountered: