I'm using dJango+uWSGI for a web project. But I found that all my logs will be written to the uwsgi log!!
The situation is that: When I write a log entry using logger.xxx, the logger I configured in settings.py will receive the log entry, but the uwsgi.log will also have a log written to that file! And the most strange things is that, in some of my projects, my application logs will be written to logs files as I configured, and all daemon process logs are written to uwsgi.log; but the other projects' application logs will ALSO be written to uwsgi.log!
Here is my logging 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 here is how I use the logging:
import logging
from time import time
logger = logging.getLogger('myproject')
logger.info('my log')
You just mix Django logging 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 add logging all requests to console and this logs handle uWSGI.
'class': 'logging.StreamHandler',
this is key for save log to uWSGI logs.
And you Django logs saves to 'filename': os.path.join(LOG_BASE, 'err.log'),
I think the problem is the daemonize tag in uwsgi.xml
The documentation (http://projects.unbit.it/uwsgi/wiki/Doc) say:
Blockquote Run the processes in background using a logfile or a udp server
--daemonize /var/log/uwsgi.log
will damonize uWSGI writing log messages to /var/log/uwsgi.log
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.