mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-13 18:17:02 +01:00
Improves the logging mixin and allows it to be typed better
This commit is contained in:
parent
37959fe31c
commit
452c79f9a1
9 changed files with 99 additions and 128 deletions
|
|
@ -3,18 +3,16 @@ import uuid
|
|||
|
||||
|
||||
class LoggingMixin:
|
||||
logging_group = None
|
||||
|
||||
logging_name = None
|
||||
def __init__(self) -> None:
|
||||
self.renew_logging_group()
|
||||
|
||||
def renew_logging_group(self):
|
||||
"""
|
||||
Creates a new UUID to group subsequent log calls together with
|
||||
the extra data named group
|
||||
"""
|
||||
self.logging_group = uuid.uuid4()
|
||||
|
||||
def log(self, level, message, **kwargs):
|
||||
if self.logging_name:
|
||||
logger = logging.getLogger(self.logging_name)
|
||||
else:
|
||||
name = ".".join([self.__class__.__module__, self.__class__.__name__])
|
||||
logger = logging.getLogger(name)
|
||||
|
||||
getattr(logger, level)(message, extra={"group": self.logging_group}, **kwargs)
|
||||
self.log = logging.LoggerAdapter(
|
||||
logging.getLogger(self.logging_name),
|
||||
extra={"group": self.logging_group},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue