Skip to content

Instantly share code, notes, and snippets.

@wangyangkobe
Forked from ibeex/foo.log
Created September 8, 2016 04:47
Show Gist options
  • Save wangyangkobe/74273d00448feb09909e2a66e37a1519 to your computer and use it in GitHub Desktop.
Save wangyangkobe/74273d00448feb09909e2a66e37a1519 to your computer and use it in GitHub Desktop.
Flask logging example
A warning occurred (42 apples)
An error occurred
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()
@wangyangkobe
Copy link
Author

fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment