Commit bade0abf authored by sim's avatar sim

[FEAT] Log django backend activity into a logfile

parent 7926620b
...@@ -4,3 +4,4 @@ __pycache__ ...@@ -4,3 +4,4 @@ __pycache__
.env .env
gargantext.ini gargantext.ini
postgrest.conf postgrest.conf
*.log
...@@ -76,6 +76,45 @@ TEMPLATES = [ ...@@ -76,6 +76,45 @@ TEMPLATES = [
WSGI_APPLICATION = 'gargantext.backend.wsgi.application' WSGI_APPLICATION = 'gargantext.backend.wsgi.application'
# Logging
LOG_LEVEL = config('LOG_LEVEL', default='DEBUG' if DEBUG else 'INFO')
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(name)s %(process)d %(threadName)s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': LOG_LEVEL,
'class': 'logging.FileHandler',
'filename': config('LOG_FILE', default='gargantext.log'),
'formatter': config('LOG_FORMATTER', default='verbose'),
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': LOG_LEVEL,
'propagate': True,
},
'django.template': {
# Don't keep debug logs for template module to avoid annoying and
# useless noise, see:
# https://github.com/encode/django-rest-framework/issues/3982#issuecomment-325290221
'level': 'INFO' if LOG_LEVEL == 'DEBUG' else LOG_LEVEL,
},
},
}
# Database # Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
...@@ -97,6 +136,7 @@ DATABASES['default']['URL'] = \ ...@@ -97,6 +136,7 @@ DATABASES['default']['URL'] = \
**DATABASES['default'] **DATABASES['default']
) )
# Password validation # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
...@@ -115,6 +155,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -115,6 +155,7 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ # https://docs.djangoproject.com/en/1.11/topics/i18n/
...@@ -128,6 +169,7 @@ USE_L10N = True ...@@ -128,6 +169,7 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ # https://docs.djangoproject.com/en/1.11/howto/static-files/
...@@ -146,6 +188,7 @@ STATICFILES_FINDERS = ( ...@@ -146,6 +188,7 @@ STATICFILES_FINDERS = (
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
# Asynchronous tasks # Asynchronous tasks
import djcelery import djcelery
...@@ -162,6 +205,7 @@ CELERY_IMPORTS = ( ...@@ -162,6 +205,7 @@ CELERY_IMPORTS = (
"gargantext.util.ngramlists_tools", "gargantext.util.ngramlists_tools",
) )
# REST-API # REST-API
# See http://getblimp.github.io/django-rest-framework-jwt/#additional-settings # See http://getblimp.github.io/django-rest-framework-jwt/#additional-settings
...@@ -202,6 +246,7 @@ API_TOKENS = { ...@@ -202,6 +246,7 @@ API_TOKENS = {
} }
} }
# BOOL Interpreter # BOOL Interpreter
BOOL_TOOLS_PATH = "gargantext/util/crawlers/sparql" BOOL_TOOLS_PATH = "gargantext/util/crawlers/sparql"
...@@ -14,6 +14,10 @@ DB_PORT = {DB_PORT} ...@@ -14,6 +14,10 @@ DB_PORT = {DB_PORT}
DB_NAME = {DB_NAME} DB_NAME = {DB_NAME}
DB_USER = {DB_USER} DB_USER = {DB_USER}
DB_PASS = {DB_PASS} DB_PASS = {DB_PASS}
# Logs
LOG_FILE = /var/log/gargantext/backend/django.log
LOG_LEVEL = {LOG_LEVEL}
LOG_FORMATTER = verbose
[uwsgi] [uwsgi]
......
...@@ -88,6 +88,8 @@ if [ -z "$TIME_ZONE" ]; then ...@@ -88,6 +88,8 @@ if [ -z "$TIME_ZONE" ]; then
TIME_ZONE=${TIME_ZONE:-UTC} TIME_ZONE=${TIME_ZONE:-UTC}
fi fi
[ "$DEBUG" = "False" ] && LOG_LEVEL=INFO || LOG_LEVEL=DEBUG
echo "▸ PostgreSQL configuration..." echo "▸ PostgreSQL configuration..."
DB_NAME_DEFAULT=gargandb DB_NAME_DEFAULT=gargandb
...@@ -144,6 +146,7 @@ DB_PORT=$(escape_ini "${DB_PORT:-5432}") ...@@ -144,6 +146,7 @@ DB_PORT=$(escape_ini "${DB_PORT:-5432}")
DB_NAME=$(escape_ini "$DB_NAME") DB_NAME=$(escape_ini "$DB_NAME")
DB_USER=$(escape_ini "$DB_USER") DB_USER=$(escape_ini "$DB_USER")
DB_PASS=$(escape_ini "$DB_PASS") DB_PASS=$(escape_ini "$DB_PASS")
LOG_LEVEL=$(escape_ini "$LOG_LEVEL")
VENV=$(escape_ini "$VENV") VENV=$(escape_ini "$VENV")
echo "▸ Generate configuration file from $GARGANTEXT_TEMPLATE..." echo "▸ Generate configuration file from $GARGANTEXT_TEMPLATE..."
...@@ -155,6 +158,7 @@ sed -E -e "s/[{]DEBUG[}]/$DEBUG/g" \ ...@@ -155,6 +158,7 @@ sed -E -e "s/[{]DEBUG[}]/$DEBUG/g" \
-e "s/[{]DB_NAME[}]/$DB_NAME/g" \ -e "s/[{]DB_NAME[}]/$DB_NAME/g" \
-e "s/[{]DB_USER[}]/$DB_USER/g" \ -e "s/[{]DB_USER[}]/$DB_USER/g" \
-e "s/[{]DB_PASS[}]/$DB_PASS/g" \ -e "s/[{]DB_PASS[}]/$DB_PASS/g" \
-e "s/[{]LOG_LEVEL[}]/$LOG_LEVEL/g" \
-e "s/[{]VENV[}]/$VENV/g" \ -e "s/[{]VENV[}]/$VENV/g" \
"$GARGANTEXT_TEMPLATE" > "$GARGANTEXT_CONF" \ "$GARGANTEXT_TEMPLATE" > "$GARGANTEXT_CONF" \
&& echo "Configuration for $TARGET environment written successfully in" \ && echo "Configuration for $TARGET environment written successfully in" \
......
Markdown is supported
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