Gitlab CSE Unil

Commit 375ae0c5 authored by Julien Furrer's avatar Julien Furrer
Browse files

Ajusté settings pour logging et email

parent 3f0682fe
...@@ -311,10 +311,20 @@ DJANGO_APPS = ( ...@@ -311,10 +311,20 @@ DJANGO_APPS = (
INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS
# ---------- END APPS CONFIGURATION # ---------- END APPS CONFIGURATION
SERVER_EMAIL = 'julien.furrer@unil.ch'
EMAIL_HOST = "smtp.unil.ch"
# ========== LOGGING CONFIGURATION # ========== LOGGING CONFIGURATION
# #
def add_remote_info(record): def add_remote_info(record):
"""
Pour utiliser, utilisez le logger comme:
logger.debug("Coucou", extra={'request': request})
:param record:
:return:
"""
req = getattr(record, 'request', None) req = getattr(record, 'request', None)
record.remote_addr = req.META.get('REMOTE_ADDR', '-') if req else '-' record.remote_addr = req.META.get('REMOTE_ADDR', '-') if req else '-'
record.forwarded_for = req.META.get('HTTP_X_FORWARDED_FOR', '-') if req else '-' record.forwarded_for = req.META.get('HTTP_X_FORWARDED_FOR', '-') if req else '-'
...@@ -334,14 +344,19 @@ LOGGING = { ...@@ -334,14 +344,19 @@ LOGGING = {
'add_remote_info': { 'add_remote_info': {
'()': 'django.utils.log.CallbackFilter', '()': 'django.utils.log.CallbackFilter',
'callback': add_remote_info, 'callback': add_remote_info,
},
'save_emails_to_disk': {
'()': 'django.utils.log.CallbackFilter',
'callback': lambda x: False,
} }
}, },
'formatters': { 'formatters': {
'verbose': { 'verbose': {
'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s %(message)s', 'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s:%(lineno)d %(message)s',
}, },
'verbose_with_remote': { 'verbose_with_remote': {
'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s %(remote_addr)s %(forwarded_for)s %(message)s', 'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s:%(lineno)d %(remote_addr)s %(forwarded_for)s %(message)s',
}, },
'simple': { 'simple': {
'format': '%(levelname)s %(message)s' 'format': '%(levelname)s %(message)s'
...@@ -351,15 +366,24 @@ LOGGING = { ...@@ -351,15 +366,24 @@ LOGGING = {
'mail_admins': { 'mail_admins': {
'level': 'ERROR', 'level': 'ERROR',
'filters': ['require_debug_false'], 'filters': ['require_debug_false'],
'include_html': False,
'class': 'django.utils.log.AdminEmailHandler' 'class': 'django.utils.log.AdminEmailHandler'
}, },
'mail_admins_file': {
'level': 'ERROR',
'filters': ['require_debug_false', 'save_emails_to_disk'],
'include_html': False,
'class': 'django.utils.log.AdminEmailHandler',
'email_backend': 'django.core.mail.backends.filebased.EmailBackend'
},
'console': { 'console': {
'filters': ['require_debug_true', ], 'filters': ['require_debug_true', ],
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
}, },
'file': { 'file_debug': {
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'logging.FileHandler', # 'class': 'logging.FileHandler',
'class': 'logging.handlers.WatchedFileHandler',
'filters': ['add_remote_info', ], 'filters': ['add_remote_info', ],
'formatter': 'verbose_with_remote', 'formatter': 'verbose_with_remote',
'filename': '{}/log/debug.log'.format(dirname(SITE_ROOT)), 'filename': '{}/log/debug.log'.format(dirname(SITE_ROOT)),
...@@ -367,7 +391,7 @@ LOGGING = { ...@@ -367,7 +391,7 @@ LOGGING = {
}, },
'loggers': { 'loggers': {
'django.request': { 'django.request': {
'handlers': ['mail_admins', 'file', ], 'handlers': ['mail_admins', 'mail_admins_file', 'file_debug', ],
'level': 'WARNING', 'level': 'WARNING',
'propagate': True, 'propagate': True,
}, },
...@@ -377,17 +401,17 @@ LOGGING = { ...@@ -377,17 +401,17 @@ LOGGING = {
'propagate': True, 'propagate': True,
}, },
'adim_app': { 'adim_app': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file_debug'],
'level': 'DEBUG', 'level': 'DEBUG',
'propagate': True, 'propagate': True,
}, },
'adim_ttp': { 'adim_ttp': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file_debug'],
'level': 'DEBUG', 'level': 'DEBUG',
'propagate': True, 'propagate': True,
}, },
'shibauth': { 'shibauth': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file_debug'],
'level': 'DEBUG', 'level': 'DEBUG',
'propagate': True, 'propagate': True,
}, },
......
...@@ -25,6 +25,7 @@ DATABASES = { ...@@ -25,6 +25,7 @@ DATABASES = {
} }
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_FILE_PATH = '{}/log/emails/current'.format(dirname(SITE_ROOT))
SENDFILE_BACKEND = 'sendfile.backends.development' SENDFILE_BACKEND = 'sendfile.backends.development'
...@@ -33,3 +34,5 @@ ADIM_DEBUG_JS = True ...@@ -33,3 +34,5 @@ ADIM_DEBUG_JS = True
INSTALLED_APPS += ('django_trap', ) INSTALLED_APPS += ('django_trap', )
DJANGO_TRAP_STORE_PW = False DJANGO_TRAP_STORE_PW = False
INTERNAL_IPS = ('127.0.0.1', '130.223.159.72')
...@@ -22,3 +22,6 @@ DATABASES = { ...@@ -22,3 +22,6 @@ DATABASES = {
ADIM_PROD = True ADIM_PROD = True
ADIM_DEBUG_JS = False ADIM_DEBUG_JS = False
# Only the ip listed here can access the admin interface
INTERNAL_IPS = ('130.223.159.72', )
...@@ -24,3 +24,6 @@ DATABASES = { ...@@ -24,3 +24,6 @@ DATABASES = {
ADIM_PROD = False ADIM_PROD = False
ADIM_DEBUG_JS = False ADIM_DEBUG_JS = False
# Only the ip listed here can access the admin interface
INTERNAL_IPS = ('130.223.159.72', )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment