Skip to content

Instantly share code, notes, and snippets.

@fanhang64
Created September 2, 2019 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanhang64/fda65a360f174c13b680d19c564d4809 to your computer and use it in GitHub Desktop.
Save fanhang64/fda65a360f174c13b680d19c564d4809 to your computer and use it in GitHub Desktop.
flask logging test
import logging
from logging.handlers import TimedRotatingFileHandler
from flask import Flask
# f_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(message)s')
fmt = '%(asctime)s - %(levelname)s - %(filename)s - %(message)s'
f_handler = TimedRotatingFileHandler('app.log', when='s', interval=1)
logging.basicConfig(
level=logging.INFO,
# filename='app.log',
format=fmt,
handlers=[f_handler, ]
)
logger = logging.getLogger(__name__)
app = Flask(__name__)
@app.route("/")
def index():
logger.info("hello world")
print("pprint text")
logger.debug('This is a debug message')
logger.info('This is an info message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('This is a critical message')
return '123'
if __name__ == "__main__":
app.run(threaded=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment