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

Commit

Permalink
Merge pull request #6251 from matrix-org/michaelkaye/debug_guard_logging
Browse files Browse the repository at this point in the history
* commit '44ab048cf':
  Address codestyle concerns
  Reduce impact of debug logging
  Delay printf until logging is required.
  use %r to __repr__ objects
  Don't encode object as UTF-8 string if not needed.
  • Loading branch information
anoadragon453 committed Mar 16, 2020
2 parents 2d9d79a + 44ab048 commit b6b4a11
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog.d/6251.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce impact of debug logging.
6 changes: 4 additions & 2 deletions synapse/crypto/event_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def compute_event_signature(event_dict, signature_name, signing_key):
redact_json = prune_event_dict(event_dict)
redact_json.pop("age_ts", None)
redact_json.pop("unsigned", None)
logger.debug("Signing event: %s", encode_canonical_json(redact_json))
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Signing event: %s", encode_canonical_json(redact_json))
redact_json = sign_json(redact_json, signature_name, signing_key)
logger.debug("Signed event: %s", encode_canonical_json(redact_json))
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Signed event: %s", encode_canonical_json(redact_json))
return redact_json["signatures"]


Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def backfill(self, dest, room_id, limit, extremities):
dest, room_id, extremities, limit
)

logger.debug("backfill transaction_data=%s", repr(transaction_data))
logger.debug("backfill transaction_data=%r", transaction_data)

room_version = yield self.store.get_room_version(room_id)
format_ver = room_version_to_event_format(room_version)
Expand Down
4 changes: 2 additions & 2 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ def backfill(self, destination, room_id, event_tuples, limit):
Deferred: Results in a dict received from the remote homeserver.
"""
logger.debug(
"backfill dest=%s, room_id=%s, event_tuples=%s, limit=%s",
"backfill dest=%s, room_id=%s, event_tuples=%r, limit=%s",
destination,
room_id,
repr(event_tuples),
event_tuples,
str(limit),
)

Expand Down
11 changes: 8 additions & 3 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ def on_GET(self, request):
full_state = parse_boolean(request, "full_state", default=False)

logger.debug(
"/sync: user=%r, timeout=%r, since=%r,"
" set_presence=%r, filter_id=%r, device_id=%r"
% (user, timeout, since, set_presence, filter_id, device_id)
"/sync: user=%r, timeout=%r, since=%r, "
"set_presence=%r, filter_id=%r, device_id=%r",
user,
timeout,
since,
set_presence,
filter_id,
device_id,
)

request_key = (user, timeout, since, filter_id, full_state, device_id)
Expand Down
14 changes: 8 additions & 6 deletions synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ async def _async_render_GET(self, request):
pattern = entry[attrib]
value = getattr(url_tuple, attrib)
logger.debug(
("Matching attrib '%s' with value '%s' against" " pattern '%s'")
% (attrib, value, pattern)
"Matching attrib '%s' with value '%s' against" " pattern '%s'",
attrib,
value,
pattern,
)

if value is None:
Expand Down Expand Up @@ -188,7 +190,7 @@ def _do_preview(self, url, user, ts):

media_info = yield self._download_url(url, user)

logger.debug("got media_info of '%s'" % media_info)
logger.debug("got media_info of '%s'", media_info)

if _is_media(media_info["media_type"]):
file_id = media_info["filesystem_id"]
Expand Down Expand Up @@ -256,7 +258,7 @@ def _do_preview(self, url, user, ts):
og["og:image:width"] = dims["width"]
og["og:image:height"] = dims["height"]
else:
logger.warn("Couldn't get dims for %s" % og["og:image"])
logger.warn("Couldn't get dims for %s", og["og:image"])

og["og:image"] = "mxc://%s/%s" % (
self.server_name,
Expand All @@ -270,7 +272,7 @@ def _do_preview(self, url, user, ts):
logger.warn("Failed to find any OG data in %s", url)
og = {}

logger.debug("Calculated OG for %s as %s" % (url, og))
logger.debug("Calculated OG for %s as %s", url, og)

jsonog = json.dumps(og)

Expand Down Expand Up @@ -299,7 +301,7 @@ def _download_url(self, url, user):

with self.media_storage.store_into_file(file_info) as (f, fname, finish):
try:
logger.debug("Trying to get url '%s'" % url)
logger.debug("Trying to get url '%s'", url)
length, headers, uri, code = yield self.client.get_file(
url, output_stream=f, max_size=self.max_spider_size
)
Expand Down
4 changes: 1 addition & 3 deletions synapse/storage/data_stores/main/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ def get_backfill_events(self, room_id, event_list, limit):
)

def _get_backfill_events(self, txn, room_id, event_list, limit):
logger.debug(
"_get_backfill_events: %s, %s, %s", room_id, repr(event_list), limit
)
logger.debug("_get_backfill_events: %s, %r, %s", room_id, event_list, limit)

event_results = set()

Expand Down

0 comments on commit b6b4a11

Please sign in to comment.