setup logging for tenants

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-11-15 15:06:29 +01:00
parent 77d8877efe
commit 4e01b80f36
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
1 changed files with 9 additions and 0 deletions

View File

@ -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