Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (57 sloc) 1.726 kb
407a89c Austin King copying input style logging
ozten authored
1 import logging
2 import logging.handlers
3
4 from django.conf import settings
5
6 import commonware.log
7 import dictconfig
8
9
10 class NullHandler(logging.Handler):
11
12 def emit(self, record):
13 pass
14
15
16 base_fmt = ('%(name)s:%(levelname)s %(message)s '
17 ':%(pathname)s:%(lineno)s')
18
19 cfg = {
20 'version': 1,
21 'filters': {},
22 'formatters': {
23 'debug': {
24 '()': commonware.log.Formatter,
25 'datefmt': '%H:%M:%s',
26 'format': '%(asctime)s ' + base_fmt,
27 },
28 'prod': {
29 '()': commonware.log.Formatter,
30 'datefmt': '%H:%M:%s',
31 'format': '%s: [%%(REMOTE_ADDR)s] %s' % (settings.SYSLOG_TAG,
32 base_fmt),
33 },
34 },
35 'handlers': {
36 'console': {
37 '()': logging.StreamHandler,
38 'formatter': 'debug',
39 },
40 'syslog': {
41 '()': logging.handlers.SysLogHandler,
42 'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
43 'formatter': 'prod',
44 },
45 'null': {
46 '()': NullHandler,
47 }
48 },
49 'loggers': {
50 'i': {},
51 },
52 'root': {},
53 }
54
55 for key, value in settings.LOGGING.items():
56 cfg[key].update(value)
57
58 # Set the level and handlers for all loggers.
59 for logger in cfg['loggers'].values() + [cfg['root']]:
60 syslog = settings.HAS_SYSLOG and not settings.DEBUG
61 if 'handlers' not in logger:
62 logger['handlers'] = ['syslog' if syslog else 'console']
63 if 'level' not in logger:
64 logger['level'] = settings.LOG_LEVEL
65 if logger is not cfg['root'] and 'propagate' not in logger:
66 logger['propagate'] = False
67
68 dictconfig.dictConfig(cfg)
69
Something went wrong with that request. Please try again.