Logging Not Registering In Flask 0.12
See original GitHub issueI’m having some trouble getting logging to work with Raven. I noticed today that the handler gets set up properly if I run Flask 0.11.1, but not on 0.12. I made some example code below which is able to reproduce the issue. I’ve been running this on Python 3.5 with just Flask and Raven installed, Raven version 5.32.0.
Symptoms
- Sentry events not reported for the below code, upon hitting the
/
route, using Flask 0.12, while events show for the same conditions using Flask 0.11.0
Expected Outcome
- Sentry events should be reported across Flask versions
import logging
from flask import Flask
from raven.contrib.flask import Sentry
sentry = Sentry()
def create_app():
app = Flask(__name__)
app.config['DEBUG'] = True
sentry.init_app(
app,
dsn='https://<redacted>',
logging=True,
level=logging.WARNING
)
def internal_server_error(exception):
app.logger.exception(exception)
return 'Internal Server Error'
app.errorhandler(Exception)(internal_server_error)
return app
app = create_app()
@app.route('/')
def test_route():
raise Exception('TEST')
if __name__ == '__main__':
app.run()
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Application Errors — Flask Documentation (0.12.x)
Error handlers are normal Pluggable Views but instead of being registered for ... ADMINS = ['yourname@example.com'] if not app.debug: import logging from ...
Read more >Flask logging - Cannot get it to write to a file - Stack Overflow
Problem with app.logger is that it is completely hardcoded. At least as of Flask 0.12.2 the logger settings of Flask (log level, log...
Read more >How to Get Started with Logging in Flask - Better Stack
Learn how to start logging with Flask and go from basics to best practices in ... Create a new working directory and change...
Read more >Flask 0.12 documentation - DevDocs
Flask 0.12.x API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >json-logging 0.0.1 - PyPI
JSON Python Logging. ... Lightweight, no dependencies, minimal configuration needed (1 LoC to get it working) ... 2.1 Non-web application log.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Tried setting
app.logger.propagate = True
and it worked as expected. Got it from https://github.com/pallets/flask/commit/e00e2c22aadf9e5b9dc353c31f1b70dad488b47aI had the same issue in Raven 6.0.0 and Flask 0.12 (logging to app.logger doesn’t propagate).
@jm66 's fix worked for me, however.