mirror of https://github.com/interlegis/sapl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
495 B
21 lines
495 B
# sapl/logging/filters.py
|
|
import logging
|
|
import contextvars
|
|
|
|
_request_id = contextvars.ContextVar("request_id", default="-")
|
|
|
|
|
|
def set_request_id(value: str):
|
|
_request_id.set(value)
|
|
|
|
|
|
def get_request_id() -> str:
|
|
return _request_id.get()
|
|
|
|
|
|
class RequestIdFilter(logging.Filter):
|
|
def filter(self, record: logging.LogRecord) -> bool:
|
|
# garante que SEMPRE existe
|
|
if not hasattr(record, "request_id"):
|
|
record.request_id = get_request_id()
|
|
return True
|
|
|