Created
September 2, 2019 06:20
-
-
Save fanhang64/fda65a360f174c13b680d19c564d4809 to your computer and use it in GitHub Desktop.
flask logging test
This file contains hidden or 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 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