首页 文章

Django StreamHandler日志在mod_wsgi设置中不起作用

提问于
浏览
0

我试图让所有日志消息转到标准的apache错误日志,我只是无法让它工作 . 如果我写一个文件就可以了,但apache日志记录不通 . 有什么建议?这是我的相关配置:

settings.py (snippet)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'filters': {
        'require_debug_false': {
           '()': 'django.utils.log.RequireDebugFalse'
        }
    },
   'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
        }
    },
    'handlers': {
        'development': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'standard',
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
    },
    'loggers': {
        '':{
            'handlers': ['development'],
            'level': 'DEBUG',
            'propagate': True
        },
        'django.db.backends': {
            'handlers': ['development'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        }
    }
}

virtual host config

<VirtualHost *:80>
    SetEnv DJANGO_DEBUG True

    ServerName virtualimpact.userhome.test-env.net

    LogLevel debug
    ErrorLog   "/home/developer/logs/developer-machine_error.log"
    CustomLog "/home/developer/logs/developer-machine_com_access.log" combined

    Alias /static/ /home/developer/htdocs/path/to/htdocs/static/

    <Directory /home/developer/htdocs/path/to/htdocs/static>
      Order deny,allow
      Allow from all
    </Directory>

    WSGIScriptAlias / /home/developer/htdocs/path/to/mod_wsgi/django.wsgi
</VirtualHost>

django.wsgi

import os, sys, site

workspace = os.path.abspath('%s/..' % os.path.dirname(__file__))
activate_this = os.path.abspath('%s/virtpy/bin/activate_this.py' % workspace)
execfile(activate_this, dict(__file__=activate_this))

sys.path.append(workspace)
sys.path.append('%s/htdocs' % workspace)

os.environ['DJANGO_SETTINGS_MODULE'] = 'htdocs.settings'
os.environ['PYTHON_EGG_CACHE'] = '%s/mod_wsgi/egg-cache' % workspace

import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()

def application(environ, start_response):
    os.environ['DJANGO_DEBUG'] = environ.get('DJANGO_DEBUG', 'False')
    return _application(environ, start_response)

views.py (snippet)

import logging
logger = logging.getLogger('')
...

class AbstractsListView(BaseListView):
    def get_context_data(self, **kwargs):
        # none of the below calls write to the error log
        logger.debug('debug it')
        logger.info('info it')
        import sys
        sys.stderr.write('asdfasdf')
        ...

如果您需要更多信息,请告诉我,这件事一直困扰着我一段时间,而且我很有智慧 .

提前致谢 .

编辑:另外,我使用的是Python 2.6.6和Django == 1.4.3

编辑:它是日志记录,但是文件错误!

所以我不知道为什么我之前没有检查,但事实证明我写入stdout(或stderr)的任何内容都会转到/ var / log / httpd /中的日志,而不是我专门配置的日志对于这个VirtualHost . 我想知道这是否比Django更像是一个mod_wsgi问题,但我不能确定 . 我的mod_wsgi和vhost.conf文件是否正确?

谢谢,

1 回答

  • 1

    好吧,这似乎源于我在嵌入模式下运行mod_wsgi而不是守护进程的事实 . 我将其切换后,我的日志开始出现在正确的位置 . 我们会看到它的票价,但到目前为止还不错 .

相关问题