Flask based app consolidated logging

Flask has an “app.logger” which you can use for webapp related logging, and for other libraries or packages that flask app is using usually python standard logging is used. There are issues reported that logs from various sources in flask based app sometimes get missed out or get messy. See the references section at the bottom for details about the issues. A workaround is to set global root logging config and override that from flask.

import logging

from flask import Flask, jsonify

app = Flask(__name__)

# config global logging
fmt = logging.Formatter(
    "[%(asctime)s] [%(process)d] [%(levelname)s] %(name)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S %z"
hlr = logging.StreamHandler()
app.logger.handlers = []
app.logger.propagate = True

def index():
    return jsonify({
        "message": "Hello, World!"

if __name__ == "__main__":


flask python