[Python] Flask and logging - some questions

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I. When creating a Flask application, where exactly do I initialize logging?
    Right before app = Flask(__name__) ?
    Right after it?

    II. By default, Flask logs HTTP requests in the common format, i.e.

    - 127.0.0.1 - - [05/Oct/2024 20:39:49] "GET / HTTP/1.1" 200 -


    How can I change it to the following?

    Received POST request "/rest/api/1234/567" from IP 192.168.0.1. Content-Type =
    "application/json", Content-Length = 12345, User-Agent = "Mozilla 1.2.3"


    III. Last but not least, does the development server included with Flask have some shutdown handler that can be registered to? When user presses Ctrl+C to kill it, I would like to perform some final cleanup operations...

    Continue reading...

Compartilhe esta Página