Flask Development Logging

Aug 29, 2018
import sysimport loggingfrom flask import Flaskapp = Flask(__name__)app.logger.setLevel(logging.DEBUG)# logging.basicConfig(level=logging.DEBUG)# logging.getLogger().setLevel(logging.DEBUG)# create a local module loggerlog = logging.getLogger(__name__)if not log.handlers:    log.setLevel(logging.DEBUG)    formatter = logging.Formatter(fmt="%(asctime)s %(levelname)s %(module)s: %(message)s",                              datefmt="%H:%M:%S")    handler = logging.StreamHandler(sys.stdout)    handler.setLevel(logging.DEBUG)    handler.setFormatter(formatter)    # log.propagate = False    log.addHandler(handler)@app.route('/')def test_logging():    app.logger.info('app.logger')    print('print')    # same as app.logger    logging.getLogger('flask.app').info('flask.app')    log.info('module log')    return 'Test logging'if __name__ == '__main__':    app.run(host='', port=8088, debug=True)


[2019-04-25 11:29:17,796] INFO in test: app.logger
[2019-04-25 11:29:17,797] INFO in test: flask.app
11:29:17 INFO test: module log - - [25/Apr/2019 11:29:17] "GET / HTTP/1.1" 200 -

NOTE: Refer to Change Flask Logging Output Format/Handler

NOTE: Refer to Flask Logging Appear Twice

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.