Skip to content Skip to sidebar Skip to footer

Uwsgi + Flask Logging.config Not Working And Also Breaks Application

Been looking for an answer for the last 5 hours and found nothing. I have a flask (python 2.7) application working fine with uwsgi but I have no logs. /etc/uwsgi/uwsgi.ini config:

Solution 1:

Well I found the problem:

"formatters": {
"simple": {
  "()": "pythonjsonlogger.jsonlogger.JsonFormatter",
  "format": "%(asctime)s %(levelname)s %(module)s %(message)s"
}

pythonjsonlogger is a library i installed manually decades ago and forgot about. It wasn't loading correctly when declaring logging.config.dictConfig().

Also, to whomever sees this, uWSGI calls only app.run() and if you want to see any logs you should declare logging before you declare app. eg:

with open("{0}/logging.config.json".format(CONFIG_PATH), "r") as fd:
    logging.config.dictConfig(json.load(fd))

app = Flask(__name__)
...
...
...
if __name__ == "__main__":
    app.run()

Post a Comment for "Uwsgi + Flask Logging.config Not Working And Also Breaks Application"