From 4e01b80f36b06c0a268928073ef19820b9b590da Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Wed, 15 Nov 2023 15:06:29 +0100 Subject: [PATCH] setup logging for tenants Signed-off-by: Marc 'risson' Schmitt --- authentik/lib/logging.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/authentik/lib/logging.py b/authentik/lib/logging.py index 682475230..ccadcf57d 100644 --- a/authentik/lib/logging.py +++ b/authentik/lib/logging.py @@ -4,6 +4,7 @@ from logging import Logger from os import getpid import structlog +from django.db import connection from authentik.lib.config import CONFIG @@ -37,6 +38,7 @@ def structlog_configure(): structlog.stdlib.add_logger_name, structlog.contextvars.merge_contextvars, add_process_id, + add_tenant_information, structlog.stdlib.PositionalArgumentsFormatter(), structlog.processors.TimeStamper(fmt="iso", utc=False), structlog.processors.StackInfoRenderer(), @@ -112,3 +114,10 @@ def add_process_id(logger: Logger, method_name: str, event_dict): """Add the current process ID""" event_dict["pid"] = getpid() return event_dict + + +def add_tenant_information(logger: Logger, method_name: str, event_dict): + event_dict["schema_name"] = connection.tenant.schema_name + event_dict["domain_url"] = getattr(connection.tenant, "domain_url", None) + + return event_dict