2010-11-09 17:58:52 +03:00
|
|
|
# Logging (copied from zamboni)
|
|
|
|
import logging
|
|
|
|
import logging.handlers
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
import commonware.log
|
|
|
|
# Currently Django does not provide dictconfig
|
|
|
|
# from django.utils.log import dictConfig
|
|
|
|
from utils.dictconfig import dictConfig
|
|
|
|
|
|
|
|
|
|
|
|
class NullHandler(logging.Handler):
|
|
|
|
|
|
|
|
def emit(self, record):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
base_fmt = ('%(name)s:%(levelname)s %(message)s '
|
|
|
|
':%(pathname)s:%(lineno)s')
|
|
|
|
|
|
|
|
cfg = {
|
|
|
|
'version': 1,
|
|
|
|
'filters': {},
|
|
|
|
'formatters': {
|
|
|
|
'debug': {
|
|
|
|
'()': commonware.log.Formatter,
|
|
|
|
'datefmt': '%H:%M:%s',
|
|
|
|
'format': '%(asctime)s ' + base_fmt,
|
|
|
|
},
|
|
|
|
'prod': {
|
|
|
|
'()': commonware.log.Formatter,
|
|
|
|
'datefmt': '%H:%M:%s',
|
2011-05-12 03:18:58 +04:00
|
|
|
'format': '%s: [%%(USERNAME)s][%%(REMOTE_ADDR)s] %s' % (settings.SYSLOG_TAG,
|
2010-11-09 17:58:52 +03:00
|
|
|
base_fmt),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
|
|
|
'()': logging.StreamHandler,
|
|
|
|
'formatter': 'debug',
|
|
|
|
},
|
|
|
|
'syslog': {
|
|
|
|
'()': logging.handlers.SysLogHandler,
|
|
|
|
'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
|
|
|
|
'formatter': 'prod',
|
|
|
|
},
|
|
|
|
'null': {
|
|
|
|
'()': NullHandler,
|
|
|
|
},
|
2011-08-19 23:03:42 +04:00
|
|
|
'mail_admins': {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'class': 'utils.admin_log.AdminEmailHandler'
|
|
|
|
}
|
2010-11-09 17:58:52 +03:00
|
|
|
},
|
|
|
|
'loggers': {
|
2010-12-30 15:03:55 +03:00
|
|
|
'f': {},
|
2011-08-19 23:13:31 +04:00
|
|
|
'django.request': {
|
|
|
|
'handlers': ['mail_admins'],
|
|
|
|
'level': 'ERROR',
|
|
|
|
'propagate': False,
|
|
|
|
}
|
2010-11-09 17:58:52 +03:00
|
|
|
},
|
|
|
|
'root': {},
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, value in settings.LOGGING.items():
|
|
|
|
cfg[key].update(value)
|
|
|
|
|
|
|
|
# Set the level and handlers for all loggers.
|
|
|
|
for logger in cfg['loggers'].values() + [cfg['root']]:
|
|
|
|
syslog = settings.HAS_SYSLOG and not settings.DEBUG
|
|
|
|
if 'handlers' not in logger:
|
|
|
|
logger['handlers'] = ['syslog' if syslog else 'console']
|
|
|
|
if 'level' not in logger:
|
|
|
|
logger['level'] = settings.LOG_LEVEL
|
|
|
|
if logger is not cfg['root'] and 'propagate' not in logger:
|
|
|
|
logger['propagate'] = False
|
|
|
|
|
|
|
|
dictConfig(cfg)
|