Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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