#
# Logging
#

# The directory where Pootle writes its logs
POOTLE_LOG_DIRECTORY = working_path("log")

# Useful references:
#
# Logging configuration:
# Django: https://docs.djangoproject.com/en/1.8/topics/logging/#configuring-logging
# RQ: https://github.com/ui/django-rq#configuring-logging
# Sentry: https://raven.readthedocs.io/en/latest/integrations/django.html#integration-with-logging
# Elasticsearch: https://elasticsearch-py.readthedocs.io/en/master/#logging
#
# Format attributes: https://docs.python.org/2/library/logging.html#logrecord-attributes
# Logging levels: https://docs.python.org/2/library/logging.html#logging-levels
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
        'action': {
            'format': '[%(asctime)s]\t%(message)s',
            'datefmt': '%Y-%m-%dT%H:%M:%S',
        },
        'rq_console': {
            'format': '%(asctime)s %(message)s',
            'datefmt': '%Y-%m-%dT%H:%M:%S',
        },
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'action'
        },
        # Log to a text file that can be rotated by logrotate
        'rq_console': {
            'level': 'DEBUG',
            'class': 'logging.handlers.WatchedFileHandler',
            'filename': os.path.join('%POOTLE_LOG_DIRECTORY%',
                                     'rqworker.log'),
            'formatter': 'rq_console',
        },
        'log_action': {
            'class': 'logging.handlers.WatchedFileHandler',
            'filename': os.path.join('%POOTLE_LOG_DIRECTORY%',
                                     'pootle-activity.log'),
            'formatter': 'action',
        },
        ## Sentry for error logging
        #'sentry': {
        #    'level': 'ERROR',
        #    'class': 'raven.contrib.django.handlers.SentryHandler',
        #},
    },
    'loggers': {
        'action': {
            'handlers': ['log_action', 'console'],
            'level': 'INFO',
            'propagate': False,
        },
        'django.db.backends': {
            'handlers': ['console'],
            'level': 'ERROR',
            'propagate': False,
        },
        'django': {
            'handlers': ['console'],
            'level': 'ERROR',
            'propagate': True,
        },
        'elasticsearch': {
            'handlers': ['console'],  # ['sentry'],
            'level': 'ERROR',
            'propagate': False,
        },
        'elasticsearch.trace': {
            'handlers': ['console'],  # ['sentry'],
            'level': 'ERROR',
            'propagate': False,
        },
        'rq.worker': {
            'handlers': ['rq_console', 'console'],  # ['sentry'],
            'level': 'INFO',
            'propagate': False,
        },
        'urllib3': {
            'level': 'WARNING',
        },
        'stats': {
            'handlers': ['rq_console'],
            'level': 'DEBUG',
            'propagate': False,
        },
        #'sentry': {
        #    'level': 'ERROR',
        #    'handlers': ['sentry',],
        #}
    },
}
