I have a flask app.py, inside the app I have a write_to_db.py script. I added logging to a catch-all decorator and now flask does not output any logging to the terminal and my VS Code debugger does not work.

When I look in the error.log file I only see the basic output like:

Running on (Press CTRL+C to quit)

import logging

logging.basicConfig(filename='eror.log', level=os.environ.get("LOGLEVEL", "CRITICAL"))

def catch_all_decorator(f):
    def wrapper(*args, **kwargs):
            f(*args, **kwargs)
            return "LOADED"
        except Exception as e:
            logging.exception("STACK TRACE")
            return "FAIL"

I need to log the stack trace data and still see it in the terminal.

1 Answers

AndreyG On Best Solutions

You over-written your default STDOUT handler with logging.basicConfig(filename='eror.log', level=os.environ.get("LOGLEVEL", "CRITICAL")).

Running on (Press CTRL+C to quit) - you see this because it actually a "print()" output and not a log output.

Here try this: logging.basicConfig(level=os.environ.get("LOGLEVEL", "CRITICAL"), handlers=[logging.FileHandler("error.log"), logging.StreamHandler()])