Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
move copy-to-parent into stop
Browse files Browse the repository at this point in the history
this really just makes `start` and `stop` more symetric. It also means that it
behaves correctly if you manually `set_log_context` rather than using the
context manager.
  • Loading branch information
richvdh committed Mar 21, 2020
1 parent 0d3fe47 commit 0c7cb65
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ def __exit__(self, type, value, traceback) -> None:
logger.warning(
"Expected logging context %s but found %s", self, current
)
# if we have a parent, pass our CPU usage stats on
if self.parent_context is not None and hasattr(
self.parent_context, "_resource_usage"
):
self.parent_context._resource_usage += self._resource_usage

# reset them in case we get entered again
self._resource_usage.reset()

def copy_to(self, record) -> None:
"""Copy logging fields from this context to a log record or
Expand Down Expand Up @@ -363,6 +355,15 @@ def stop(self) -> None:

self.usage_start = None

# if we have a parent, pass our CPU usage stats on
if self.parent_context is not None and hasattr(
self.parent_context, "_resource_usage"
):
self.parent_context._resource_usage += self._resource_usage

# reset them in case we get entered again
self._resource_usage.reset()

def get_resource_usage(self) -> ContextResourceUsage:
"""Get resources used by this logcontext so far.
Expand Down

0 comments on commit 0c7cb65

Please sign in to comment.