Created
August 4, 2012 13:46
-
Star
(312)
You must be signed in to star a gist -
Fork
(64)
You must be signed in to fork a gist
-
-
Save ibeex/3257877 to your computer and use it in GitHub Desktop.
Flask logging example
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
A warning occurred (42 apples) | |
An error occurred |
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 logging.handlers import RotatingFileHandler | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def foo(): | |
app.logger.warning('A warning occurred (%d apples)', 42) | |
app.logger.error('An error occurred') | |
app.logger.info('Info') | |
return "foo" | |
if __name__ == '__main__': | |
handler = RotatingFileHandler('foo.log', maxBytes=10000, backupCount=1) | |
handler.setLevel(logging.INFO) | |
app.logger.addHandler(handler) | |
app.run() |
is there a way to log errors (ex: timeout connection DB) inside gunicorn logs? Or how should I log errors in a flask app running in production with Gunicorn?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot!