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 /> <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')