Why are all application logs written to the uwsgi log?

I am using dJango + uWSGI for a web project. But I found that all my logs will be written to the uwsgi log.

The situation is this: when I write a log entry using logger.xxx, the log configured in settings.py will receive the log entry, but uwsgi.log will also have a log written to this file! And the strangest thing is that in some of my projects my application logs will be written to the log files as I was configured, and all daemon process logs are written to uwsgi.log; but other project application logs will ALSO be written to uwsgi.log!

Here is my registration configuration:

LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, 'detail': { 'format': '%(asctime)s %(levelname)s %(module)s %(message)s' }, 'message_only': { 'format': '%(asctime)s %(message)s' }, 'simple': { 'format': '%(levelname)s %(asctime)s %(message)s' }, }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler' }, 'file':{ 'level':'DEBUG', 'class':'logging.handlers.TimedRotatingFileHandler', 'formatter': 'simple', 'filename': os.path.join(LOG_BASE, 'web.log'), 'when': 'D', 'backupCount' : 3 }, 'pref':{ 'level':'DEBUG', 'class':'logging.handlers.RotatingFileHandler', 'formatter': 'message_only', 'filename': os.path.join(LOG_BASE, 'pref.log'), 'maxBytes': 10 * 1024 * 1024, # 10MB 'backupCount' : 5 }, 'err':{ 'level':'ERROR', 'class':'logging.handlers.TimedRotatingFileHandler', 'formatter': 'detail', 'filename': os.path.join(LOG_BASE, 'err.log'), 'when': 'D', 'backupCount' : 3 }, }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'myproject' : { 'handlers': ['file', 'err' ], 'level': 'INFO', }, 'myproject+prefs' : { 'handlers': ['pref'], 'level': 'DEBUG', } } } 

And my uwsgi.xml:

 <uwsgi> <socket>:8888</socket> <env>DJANGO_SETTINGS_MODULE=myproject.settings</env> <module>django.core.handlers.wsgi:WSGIHandler()</module> <processes>4</processes> <master /> <master-as-root /> <!-- request timeout --> <harakiri>15</harakiri> <post-buffering>32768</post-buffering> <daemonize>/var/log/myproject/uwsgi.log</daemonize> <listen>32768</listen> <socket-timeout>4</socket-timeout> <disable-logging /> </uwsgi> 

And this is how I use logging:

 import logging from time import time logger = logging.getLogger('myproject') logger.info('my log') 
+4
source share
2 answers

You just mix the Django registration system and uWSGI.

 'formatters': { 'simple': { 'format': '%(levelname)s | %(message)s' }, ... }, 'handlers': { 'console':{ 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'simple' }, ... }, 'loggers': { 'django.request': { 'handlers': ['console', ], 'level': 'DEBUG', 'propagate': True, }, }, 

this adds logging of all requests to the console, and these logs process uWSGI.

'class': 'logging.StreamHandler', This is the key to save the log in uWSGI logs.

And your Django logs are saved until 'filename': os.path.join(LOG_BASE, 'err.log'),

+5
source

I think the problem is the daemonize tag in uwsgi.xml

The documentation (http://projects.unbit.it/uwsgi/wiki/Doc) says:

Blockquote Run processes in the background using a log file or udp server

- daemonize / var / log / uwsgi.log

will cause damonize uWSGI by writing log messages to /var/log/uwsgi.log

0
source

Source: https://habr.com/ru/post/1386078/


All Articles