Last active
November 2, 2017 14:05
-
-
Save ashwoods/eededc34155e3f5d43128cbe591665c9 to your computer and use it in GitHub Desktop.
logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from flask import Flask | |
from raven.contrib.flask import Sentry | |
logger = logging.getLogger(__name__) | |
app = Flask(__name__) | |
app.config['DEBUG'] = False | |
sentry = Sentry( | |
app, | |
logging=True, | |
dsn='https://XXXXX:[email protected]/XXXXX', | |
level=logging.DEBUG | |
) | |
# if you use the same, you will get the same logger | |
assert app.logger.name == "simple_app" | |
assert logger == app.logger | |
assert app.logger.parent.name == "root" | |
assert app.logger.parent.parent is None | |
# you can create hierarchies using dot notations | |
child_logger = logging.getLogger("simple_app.child") | |
assert child_logger.name == "simple_app.child" | |
assert child_logger.parent.name == "simple_app" | |
assert child_logger.parent == app.logger | |
grandchild_logger = logging.getLogger("simple_app.child.grandchild") | |
assert grandchild_logger.parent.parent == app.logger | |
# events are tied to a project, in order to have different loggers report to different projects | |
# you have add a SentryHandler to the child loggers with a unique client for each project. | |
@app.route("/") | |
def hello(): | |
try: | |
1/0 | |
except: | |
sentry.captureException() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment