2012-10-04 13:07:41 +04:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from django.conf import settings
|
2012-10-08 13:12:31 +04:00
|
|
|
from django.utils.log import dictConfig
|
2012-10-04 13:07:41 +04:00
|
|
|
|
|
|
|
import celery.conf
|
|
|
|
import celery.log
|
|
|
|
|
2012-10-04 22:43:53 +04:00
|
|
|
config = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': True,
|
2012-11-30 22:43:00 +04:00
|
|
|
'root': {
|
|
|
|
'level': logging.ERROR,
|
2012-12-01 02:27:47 +04:00
|
|
|
'handlers': ['sentry'],
|
2012-11-30 22:43:00 +04:00
|
|
|
},
|
2012-10-04 22:43:53 +04:00
|
|
|
'formatters': {
|
|
|
|
'default': {
|
|
|
|
'format': '{0}: %(asctime)s %(name)s:%(levelname)s %(message)s: '
|
|
|
|
'%(pathname)s:%(lineno)s'.format(settings.SYSLOG_TAG),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'syslog': {
|
|
|
|
'class': 'logging.handlers.SysLogHandler',
|
|
|
|
'formatter': 'default',
|
|
|
|
'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
|
|
|
|
'level': settings.LOG_LEVEL,
|
|
|
|
},
|
|
|
|
'mail_admins': {
|
|
|
|
'class': 'django.utils.log.AdminEmailHandler',
|
|
|
|
'level': logging.ERROR,
|
|
|
|
},
|
2012-11-30 22:43:00 +04:00
|
|
|
'sentry': {
|
|
|
|
'class': 'raven.contrib.django.handlers.SentryHandler',
|
|
|
|
'level': logging.ERROR,
|
|
|
|
},
|
2012-10-04 22:43:53 +04:00
|
|
|
'console': {
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'default',
|
|
|
|
'level': settings.LOG_LEVEL,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'k': {
|
2012-12-01 02:27:47 +04:00
|
|
|
'handlers': ['syslog', 'mail_admins'],
|
2012-10-04 22:43:53 +04:00
|
|
|
'propogate': True,
|
|
|
|
# Use the most permissive setting. It is filtered in the handlers.
|
|
|
|
'level': logging.DEBUG,
|
2012-10-10 16:26:22 +04:00
|
|
|
},
|
|
|
|
'django.request': {
|
2012-12-01 02:27:47 +04:00
|
|
|
'handlers': ['syslog', 'mail_admins'],
|
2012-10-10 16:26:22 +04:00
|
|
|
'propogate': True,
|
|
|
|
# Use the most permissive setting. It is filtered in the handlers.
|
|
|
|
'level': logging.DEBUG,
|
|
|
|
},
|
2012-11-30 22:43:00 +04:00
|
|
|
'raven': {
|
|
|
|
'level': logging.ERROR,
|
|
|
|
'handlers': ['syslog', 'mail_admins'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
|
|
|
'sentry.errors': {
|
|
|
|
'level': logging.ERROR,
|
|
|
|
'handlers': ['syslog', 'mail_admins'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
2012-10-04 22:43:53 +04:00
|
|
|
},
|
|
|
|
}
|
2012-10-04 13:07:41 +04:00
|
|
|
|
|
|
|
if settings.DEBUG:
|
2012-10-04 22:43:53 +04:00
|
|
|
config['formatters']['default']['datefmt'] = '%H:%M:%S'
|
|
|
|
config['loggers']['k']['handlers'] = ['console']
|
2012-10-10 16:26:22 +04:00
|
|
|
config['loggers']['django.request']['handlers'] = ['console']
|
2012-10-04 13:07:41 +04:00
|
|
|
else:
|
|
|
|
task_log = logging.getLogger('k.celery')
|
|
|
|
task_proxy = celery.log.LoggingProxy(task_log)
|
|
|
|
celery.conf.CELERYD_LOG_FILE = task_proxy
|
|
|
|
celery.conf.CELERYD_LOG_COLOR = False
|
2012-10-04 22:43:53 +04:00
|
|
|
|
2012-10-08 13:12:31 +04:00
|
|
|
dictConfig(config)
|