question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging Not Registering In Flask 0.12

See original GitHub issue

I’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:open
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jm66commented, Feb 8, 2017

Tried setting app.logger.propagate = True and it worked as expected. Got it from https://github.com/pallets/flask/commit/e00e2c22aadf9e5b9dc353c31f1b70dad488b47a

0reactions
ghostcommented, Apr 18, 2017

I 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found