WSL/SLF GitLab Repository

Commit 04572466 authored by Sam's avatar Sam
Browse files

feat: add correct logging to Django throughout app, LOG_LEVEL setting

parent 9477d65e
......@@ -75,6 +75,7 @@ GCNET_DB_xxx settings.
ALLOWED_HOSTS='["<IP or Domain>", "<IP or Domain>"]'
PORT=<port number used by NGINX server in runserver.py>
PROXY_PREFIX=<Optional URL prefix if required / served behind a proxy>
LOG_LEVEL=<Log level for app printing to STDOUT>
DATABASE_NAME=<db_name>
DATABASE_USER=<db_user>
......
......@@ -14,6 +14,7 @@ Requires secrets to be pre-populated.
- key: SECRET_KEY (random, for Django)
- key: ALLOWED_HOSTS (server to access from)
- key: PROXY_PREFIX (url prefix, if behind proxy)
- key: LOG_LEVEL
- key: PORT
- key: DATABASE_NAME
- key: DATABASE_USER
......@@ -26,6 +27,7 @@ Requires secrets to be pre-populated.
--from-literal=SECRET_KEY=xxxxxxx \
--from-literal=ALLOWED_HOSTS='["envidat.ch", "monitoring.envidat.ch"]' \
--from-literal=PROXY_PREFIX=/data-api \
--from-literal=LOG_LEVEL=DEBUG \
--from-literal=PORT=8080 \
--from-literal=DATABASE_NAME=xxxxxxx \
--from-literal=DATABASE_USER=xxxxxxx \
......
......@@ -11,12 +11,12 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import json
import logging
import logging.config
import os
import environ
log = logging.getLogger()
log = logging.getLogger(__name__)
env = environ.Env()
# Reading .env file
......@@ -125,6 +125,36 @@ DATABASES = {
},
}
# Logging
LOGGING_CONFIG = None
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"console": {
"format": (
"%(asctime)s.%(msecs)03d [%(levelname)s] "
"%(name)s | %(funcName)s:%(lineno)d | %(message)s"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "console",
},
},
"loggers": {
"": {
"level": env("LOG_LEVEL", default="DEBUG"),
"handlers": ["console"],
},
},
}
)
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......
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