-
-
Save bashkirtsevich/1e64c82b8e55a5af76cb1b730601d34d 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment