Flask and logging – some questions /u/pachura3 Python Education

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…

submitted by /u/pachura3
[link] [comments]

​r/learnpython 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… submitted by /u/pachura3 [link] [comments] 

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…

submitted by /u/pachura3
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *