tiangolo / meinheld-gunicorn-flask-docker

Docker image with Meinheld and Gunicorn for Flask applications in Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

print logs not displaying in log file until reboot of container

bignellrp opened this issue · comments

I have switched from using "tiangolo / uwsgi-nginx-flask-docker" to now using "tiangolo / meinheld-gunicorn-flask-docker"

I have noticed that previously my "print" logs would display immediately in the log file. I use these logs for troubleshooting and validation within the app to make sure the functions have performed as expected. e.g. "Updating score" in the example from my old docker.

uwsgi-nginx-flask-docker Example:

[pid: 22|app: 0|req: 8/14] 192.168.0.229 () {48 vars in 797 bytes} [Wed Sep 1 19:56:16 2021] GET / => generated 14303 bytes in 1213 msecs (HTTP/1.1 200) 2 headers in 82 bytes (1 switches on core 0) 192.168.0.229 - - [01/Sep/2021:19:56:17 +0100] "GET / HTTP/1.1" 200 14303 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/92.0.4515.90 Mobile/15E148 Safari/604.1" "192.168.0.1" [pid: 21|app: 0|req: 7/15] 192.168.0.229 () {50 vars in 860 bytes} [Wed Sep 1 19:56:19 2021] GET /score => generated 7178 bytes in 578 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0) 192.168.0.229 - - [01/Sep/2021:19:56:20 +0100] "GET /score HTTP/1.1" 200 7178 "" "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/92.0.4515.90 Mobile/15E148 Safari/604.1" "192.168.0.1" Updating score Results!B22

Now using meinheld-gunicorn-flask-docker i dont get any of the http logging or my print messages in the live log. Until i reboot then i get my print messages all come in at once but still no http logs. See in the example below that the message "Wiping tally!" only appeared AFTER i rebooted the container.

Is it something to do with loglevels? If so how do i set the log level? Or could it be that im running async and its blocking the logs?

meinheld-gunicorn-flask-docker Example:

`
[2021-09-04 19:29:53 +0100] [1] [INFO] Using worker: egg:meinheld#gunicorn_worker
[2021-09-04 19:29:53 +0100] [8] [INFO] Booting worker with pid: 8
Exception in callback Cron.set_result(<_GatheringFu...ute 'send'")]>)
handle: <Handle Cron.set_result(<_GatheringFu...ute 'send'")]>)>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.8/site-packages/aiocron/init.py", line 100, in set_result
raise result
File "/app/cogs/cron.py", line 22, in cronmsg
await channel.send('Whos available to play this week?')
AttributeError: 'NoneType' object has no attribute 'send'
[2021-09-05 11:07:08 +0100] [1] [INFO] Handling signal: term
[2021-09-05 11:07:08 +0100] [8] [INFO] Worker exiting (pid: 8)
{"loglevel": "info", "workers": 1, "bind": "0.0.0.0:80", "workers_per_core": 2.0, "host": "0.0.0.0", "port": "80"}
IF branch is:pro
Git branch is:pre

Using Dev Worksheet for Get Commands
footyappdev logged in successfully
Wiping tally!
Checking for script in /app/prestart.sh
There is no script /app/prestart.sh
[2021-09-05 11:07:19 +0100] [1] [INFO] Starting gunicorn 20.0.4
[2021-09-05 11:07:19 +0100] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2021-09-05 11:07:19 +0100] [1] [INFO] Using worker: egg:meinheld#gunicorn_worker
[2021-09-05 11:07:19 +0100] [8] [INFO] Booting worker with pid: 8
`

Ps I set the log level to debug using -e LOG_LEVEL="debug" but it only made the process itself more verbose but still no print or http logs until I reboot the container.

PPS I removed all discord and async and just loaded pure flask and the result was the same. No print messages until i restart the container. Can someone suggest what im doing wrong?

Added -e PYTHONUNBUFFERED="1" which seems to have solved my issue.