Commit bade0abf authored by sim's avatar sim

[FEAT] Log django backend activity into a logfile

parent 7926620b
......@@ -4,3 +4,4 @@ __pycache__
.env
gargantext.ini
postgrest.conf
*.log
......@@ -76,6 +76,45 @@ TEMPLATES = [
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
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
......@@ -97,6 +136,7 @@ DATABASES['default']['URL'] = \
**DATABASES['default']
)
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
......@@ -115,6 +155,7 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
......@@ -128,6 +169,7 @@ USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
......@@ -146,6 +188,7 @@ STATICFILES_FINDERS = (
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Asynchronous tasks
import djcelery
......@@ -162,6 +205,7 @@ CELERY_IMPORTS = (
"gargantext.util.ngramlists_tools",
)
# REST-API
# See http://getblimp.github.io/django-rest-framework-jwt/#additional-settings
......@@ -202,6 +246,7 @@ API_TOKENS = {
}
}
# BOOL Interpreter
BOOL_TOOLS_PATH = "gargantext/util/crawlers/sparql"
......@@ -14,6 +14,10 @@ DB_PORT = {DB_PORT}
DB_NAME = {DB_NAME}
DB_USER = {DB_USER}
DB_PASS = {DB_PASS}
# Logs
LOG_FILE = /var/log/gargantext/backend/django.log
LOG_LEVEL = {LOG_LEVEL}
LOG_FORMATTER = verbose
[uwsgi]
......
......@@ -88,6 +88,8 @@ if [ -z "$TIME_ZONE" ]; then
TIME_ZONE=${TIME_ZONE:-UTC}
fi
[ "$DEBUG" = "False" ] && LOG_LEVEL=INFO || LOG_LEVEL=DEBUG
echo "▸ PostgreSQL configuration..."
DB_NAME_DEFAULT=gargandb
......@@ -144,6 +146,7 @@ DB_PORT=$(escape_ini "${DB_PORT:-5432}")
DB_NAME=$(escape_ini "$DB_NAME")
DB_USER=$(escape_ini "$DB_USER")
DB_PASS=$(escape_ini "$DB_PASS")
LOG_LEVEL=$(escape_ini "$LOG_LEVEL")
VENV=$(escape_ini "$VENV")
echo "▸ Generate configuration file from $GARGANTEXT_TEMPLATE..."
......@@ -155,6 +158,7 @@ sed -E -e "s/[{]DEBUG[}]/$DEBUG/g" \
-e "s/[{]DB_NAME[}]/$DB_NAME/g" \
-e "s/[{]DB_USER[}]/$DB_USER/g" \
-e "s/[{]DB_PASS[}]/$DB_PASS/g" \
-e "s/[{]LOG_LEVEL[}]/$LOG_LEVEL/g" \
-e "s/[{]VENV[}]/$VENV/g" \
"$GARGANTEXT_TEMPLATE" > "$GARGANTEXT_CONF" \
&& 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