policies: improve debug logging

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-21 19:10:15 +02:00
parent 75f252b530
commit 41a1305555
2 changed files with 14 additions and 4 deletions

View File

@ -105,16 +105,21 @@ class PolicyEngine:
if cached_policy and self.use_cache: if cached_policy and self.use_cache:
self.logger.debug( self.logger.debug(
"P_ENG: Taking result from cache", "P_ENG: Taking result from cache",
policy=binding.policy, binding=binding,
cache_key=key, cache_key=key,
request=self.request,
) )
self.__cached_policies.append(cached_policy) self.__cached_policies.append(cached_policy)
continue continue
self.logger.debug("P_ENG: Evaluating policy", policy=binding.policy) self.logger.debug(
"P_ENG: Evaluating policy", binding=binding, request=self.request
)
our_end, task_end = Pipe(False) our_end, task_end = Pipe(False)
task = PolicyProcess(binding, self.request, task_end) task = PolicyProcess(binding, self.request, task_end)
task.daemon = False task.daemon = False
self.logger.debug("P_ENG: Starting Process", policy=binding.policy) self.logger.debug(
"P_ENG: Starting Process", binding=binding, request=self.request
)
if not CURRENT_PROCESS._config.get("daemon"): if not CURRENT_PROCESS._config.get("daemon"):
task.run() task.run()
else: else:

View File

@ -51,7 +51,12 @@ class PolicyRequest:
LOGGER.warning("failed to get geoip data", exc=exc) LOGGER.warning("failed to get geoip data", exc=exc)
def __str__(self): def __str__(self):
return f"<PolicyRequest user={self.user}>" text = f"<PolicyRequest user={self.user}"
if self.obj:
text += f" obj={self.obj}"
if self.http_request:
text += f" http_request={self.http_request}"
return text + ">"
@dataclass @dataclass