~ya-bo-ng/ubuntu-webcatalog/description-styling-update

« back to all changes in this revision

Viewing changes to src/webcatalog/wsgi.py

[r=lukasz-czyzykowski] Separate logging configs for webapp and import command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""wsgi stack for the Apps Directory."""
19
19
 
 
20
import logging.config
20
21
import oops_dictconfig
21
22
import oops_wsgi
22
23
import oops_wsgi.django
27
28
from django.core.handlers import wsgi
28
29
 
29
30
 
 
31
logging_dict = {
 
32
    'version': 1,
 
33
    'disable_existing_loggers': True,
 
34
    'handlers': {
 
35
        'webapp': {
 
36
            'class': 'logging.handlers.WatchedFileHandler',
 
37
            'level': 'INFO',
 
38
            'formatter': 'simple',
 
39
            'filename': settings.WEBAPP_LOG_PATH,
 
40
        },
 
41
    },
 
42
    'root': {
 
43
        'handlers': ['webapp'],
 
44
        'level': 'INFO',
 
45
    },
 
46
    'loggers': {
 
47
        # Ensure django log messages are propagated to our
 
48
        # above root logger.
 
49
        'django': {
 
50
            'handlers': [],
 
51
            'propagate': True,
 
52
        }
 
53
    },
 
54
    'formatters': {
 
55
        'simple': {
 
56
            'format': settings.LOG_FORMAT,
 
57
        }
 
58
    }
 
59
}
 
60
 
 
61
 
30
62
class EagerOOPSWSGIHandler(wsgi.WSGIHandler):
31
63
    """Pre-generates an oops id on exception."""
32
64
    def handle_uncaught_exception(self, request, resolver, exc_info):
62
94
    if settings.SHOULD_SERVE_HTTPS:
63
95
        os.environ['HTTPS'] = 'on'
64
96
 
 
97
    # We configure logging here rather than the default settings
 
98
    # because not every process using ./manage.py has file perms
 
99
    # for the webapp log.
 
100
    logging.config.dictConfig(logging_dict)
65
101
    non_oops_app = EagerOOPSWSGIHandler()
66
102
 
67
103
    config = oops_dictconfig.config_from_dict(settings.OOPSES)