Uwsgi only sending stdout logs to GCP in Kubernetes Engine
I have a django application for which I want to send logs to GCP.
Locally, everything works fine using django dev server and Cloud Logging for Python. I see the logs on my GCP dashboard with the right level, I can also see the json structured logs when I use them. It also works well when I'm using gunicorn in a local docker instead of the django dev server.
However, as soon as I'm using uwsgi locally, I can't find any trace of my logs in the GCP dashboard. When I deploy my docker image in Kubernetes Engine, all the logs are only displayed as info and they are not json structured anymore. I noticed that the logger name is stdout
in my log explorer.
I'm supposing that somehow uwsgi don't use my python logging config and only logs to stdout
that is automatically sent as info by some internal gcp process.
Here's my uwsgi.ini
:
[uwsgi]
chdir=xxx
module=xxx
http = 0.0.0.0:8080
vacuum = true
enable-threads = true
listen = 128
# socket-timeout, http-timeout and harakiri are in s
socket-timeout = 180
http-timeout = 180
harakiri = 180
harakiri-verbose = true
py-autoreload = false
processes = 4
memory-report = false
master = true
master-fifo = /tmp/master-fifo
post-buffering = 65536
buffer-size = 65535
max-requests = 1500
max-requests-delta = 100
max-worker-lifetime = 3600
hook-accepting1-once = write:/tmp/bkm.ready ok
# Logging configuration
# Disable request logging. It's done from the application
disable-logging = true
log-master = false
# this will only prefix system logs
log-prefix = [uWSGI]
and my logging configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'formatters': {
'verbose': {
'format': '%(name)s [%(module)s:%(funcName)s:%(lineno)d] > %(message)s',
},
'simple': {
'format': '%(levelname)s > %(message)s',
},
},
'handlers': {
'console_simple': {
'class': 'logging.StreamHandler',
'filters': ['require_debug_true'],
'formatter': 'simple',
'level': 'DEBUG',
},
'console_verbose': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'level': 'INFO',
},
'slack': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'api.project.logger.SlackHandler',
},
'stackdriver_logging': {
'level': 'INFO',
'class': 'google.cloud.logging_v2.handlers.CloudLoggingHandler',
'formatter': 'verbose',
'client': logging_v2.Client(),
'labels': {'env': ENV_LABEL},
},
},
'loggers': {
'api': {
'handlers': [
# 'console_simple',
'console_verbose',
'stackdriver_logging',
'slack',
],
'level': 'DEBUG',
'propagate': False,
},
},
'root': {
'handlers': ['console_verbose'],
'level': 'DEBUG',
},
}
I've tried different configuration of uwsgi (log-master
, log-encoder
...) but without any luck. I can correctly see my logs when I use gunicorn that's why I suspect uwsgi to be the cause but I'd like to avoid changing my wsgi server if possible.
Thanks