File: log.py

package info (click to toggle)
python-django-pgschemas 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: python: 3,887; makefile: 33; sh: 10; sql: 2
file content (28 lines) | stat: -rw-r--r-- 825 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
from typing import Any

from django_pgschemas.routing.info import DomainInfo, HeadersInfo, SessionInfo
from django_pgschemas.schema import get_current_schema


class SchemaContextFilter(logging.Filter):
    """
    Add the current routing info to log records.
    """

    def filter(self, record: Any) -> bool:
        current_schema = get_current_schema()
        record.schema_name = current_schema.schema_name

        match current_schema.routing:
            case DomainInfo(domain, folder):
                record.domain = domain
                record.folder = folder
            case SessionInfo(reference):
                record.reference = reference
            case HeadersInfo(reference):
                record.reference = reference
            case _:
                pass

        return True