Improved logging
This commit is contained in:
parent
045391fc59
commit
aa476b4318
|
|
@ -7,6 +7,8 @@ from pathlib import Path
|
|||
import structlog
|
||||
from environs import Env
|
||||
|
||||
from core.utils import add_app_info
|
||||
|
||||
SERVER_ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
|
||||
# vbv_lernwelt/
|
||||
APPS_DIR = SERVER_ROOT_DIR / "vbv_lernwelt"
|
||||
|
|
@ -44,7 +46,7 @@ LOCALE_PATHS = [str(SERVER_ROOT_DIR / "locale")]
|
|||
# DATABASES
|
||||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {"default": env.dj_db_url("VBV_DATABASE_URL")}
|
||||
DATABASES = {"default": env.dj_db_url("VBV_DATABASE_URL", default="postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt")}
|
||||
DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405
|
||||
DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405
|
||||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||
|
|
@ -294,7 +296,6 @@ else:
|
|||
"formatters": {
|
||||
"json": {
|
||||
"()": "pythonjsonlogger.jsonlogger.JsonFormatter",
|
||||
# noqa I004
|
||||
"format": "%(asctime)s %(msecs)03d %(process)d %(thread)d %(levelname)s %(name)s %(filename)s %(lineno)d %(funcName)s %(message)s", # noqa I004
|
||||
"datefmt": "%Y-%m-%dT%H:%M:%S",
|
||||
},
|
||||
|
|
@ -340,6 +341,7 @@ else:
|
|||
processors=[
|
||||
structlog.threadlocal.merge_threadlocal,
|
||||
structlog.stdlib.filter_by_level,
|
||||
add_app_info,
|
||||
structlog.stdlib.PositionalArgumentsFormatter(),
|
||||
structlog.processors.StackInfoRenderer(),
|
||||
structlog.processors.format_exc_info,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export VBV_DATABASE_URL='postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt'
|
||||
export VBV_DJANGO_LOGGING_CONF=VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR
|
||||
#export VBV_DJANGO_LOGGING_CONF=VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR
|
||||
export VBV_DJANGO_DEBUG=True
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from structlog.types import EventDict
|
||||
|
||||
|
||||
def add_app_info(
|
||||
logger: logging.Logger, method_name: str, event_dict: EventDict
|
||||
) -> EventDict:
|
||||
event_dict["django_app"] = "vbv_lernwelt"
|
||||
event_dict["django_dev_mode"] = settings.DJANGO_DEV_MODE
|
||||
|
||||
return event_dict
|
||||
Loading…
Reference in New Issue