Skip to content

Commit

Permalink
Handle all 3 loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
abarolo authored and abarolo committed Mar 27, 2024
1 parent c8018b3 commit 5bb393d
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,67 +351,57 @@
# ============================================
DJANGO_LOG_LEVEL = env("DJANGO_LOG_LEVEL", default="info").upper()

ENABLED_HANDLERS = env.list("ENABLED_LOGGING_HANDLERS", default=["ecs", "stdout"])

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"asim_formatter": {"()": ASIMFormatter},
"ecs_formatter": {"()": ECSFormatter},
"simple": {
"format": "{asctime} {levelname} {message}",
"style": "{",
},
},
"handlers": {
"asim": {
"class": "logging.StreamHandler",
"stream": sys.stdout, # noqa F405
"formatter": "asim_formatter",
},
"ecs": {
"class": "logging.StreamHandler",
"stream": sys.stdout, # noqa F405
"formatter": "ecs_formatter",
},
"stdout": {
"class": "logging.StreamHandler",
"stream": sys.stdout, # noqa F405
"formatter": "simple",
},
},
"root": {
"handlers": ["asim", "ecs", "stdout"],
"level": os.getenv("ROOT_LOG_LEVEL", "INFO"), # noqa F405
},
"loggers": {
"django": {
"handlers": ["asim", "ecs", "stdout"],
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), # noqa F405
"propagate": False,
},
"django.server": {
"handlers": ["asim", "ecs", "stdout"],
"level": os.getenv("DJANGO_SERVER_LOG_LEVEL", "ERROR"), # noqa F405
"propagate": False,
},
"django.db.backends": {
"handlers": ["asim", "ecs", "stdout"],
"level": os.getenv("DJANGO_DB_LOG_LEVEL", "ERROR"), # noqa F405
"propagate": False,
},
},
}

# Switch logging based on gov paas vs dbt platform.
if is_copilot():
LOGGING["formatters"]["asim_formatter"] = {"()": ASIMFormatter}
LOGGING["handlers"]["asim"] = {
"class": "logging.StreamHandler",
"stream": sys.stdout, # noqa F405
"formatter": "asim_formatter",
}
LOGGING["root"] = {"handlers": ["asim"]}
LOGGING["loggers"]["django"]["handlers"] = ["asim"]
LOGGING["loggers"]["django.server"]["handlers"] = ["asim"]
LOGGING["loggers"]["django.db.backends"]["handlers"] = ["asim"]
else:
LOGGING["formatters"]["ecs_formatter"] = {"()": ECSFormatter}
LOGGING["handlers"]["ecs"] = {
"class": "logging.StreamHandler",
"stream": sys.stdout, # noqa F405
"formatter": "ecs_formatter",
}
LOGGING["root"] = {"handlers": ENABLED_HANDLERS}
LOGGING["loggers"]["django"]["handlers"] = ENABLED_HANDLERS
LOGGING["loggers"]["django.server"]["handlers"] = ENABLED_HANDLERS
LOGGING["loggers"]["django.db.backends"]["handlers"] = ENABLED_HANDLERS

# Django Log Formatter ASIM settings
if is_copilot():
DLFA_TRACE_HEADERS = ("X-B3-TraceId", "X-B3-SpanId")
Expand Down

0 comments on commit 5bb393d

Please sign in to comment.