logging: Pass more format arguments to logging.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-06-02 20:51:16 -07:00 committed by Tim Abbott
parent dede49ad78
commit a7f9c4f958
6 changed files with 27 additions and 28 deletions

View File

@ -214,11 +214,11 @@ while True:
# Catch up on any historical columns # Catch up on any historical columns
while True: while True:
rows_updated = update_fts_columns(cursor) rows_updated = update_fts_columns(cursor)
notice = f"process_fts_updates: Processed {rows_updated} rows catching up" logger.log(
if rows_updated > 0: logging.INFO if rows_updated > 0 else logging.DEBUG,
logger.info(notice) "process_fts_updates: Processed %d rows catching up",
else: rows_updated,
logger.debug(notice) )
if rows_updated != BATCH_SIZE: if rows_updated != BATCH_SIZE:
# We're caught up, so proceed to the listening for updates phase. # We're caught up, so proceed to the listening for updates phase.

View File

@ -86,14 +86,12 @@ def check_html_templates(templates: Iterable[str], all_dups: bool, fix: bool) ->
} }
for ids, fns in ignorable_ids_dict.items(): for ids, fns in ignorable_ids_dict.items():
logging.warning( logging.warning("Duplicate ID(s) detected: ID %r present at following files:", ids)
"Duplicate ID(s) detected :Id '" + ids + "' present at following files:"
)
for fn in fns: for fn in fns:
print(fn) print(fn)
for ids, fns in bad_ids_dict.items(): for ids, fns in bad_ids_dict.items():
logging.error("Duplicate ID(s) detected :Id '" + ids + "' present at following files:") logging.error("Duplicate ID(s) detected: ID %r present at following files:", ids)
for fn in fns: for fn in fns:
print(fn) print(fn)
return bad_ids_dict return bad_ids_dict

View File

@ -46,12 +46,13 @@ rules:
languages: [python] languages: [python]
patterns: patterns:
- pattern-either: - pattern-either:
- pattern: $LOGGER.debug($FORMATTED) - pattern: $LOGGER.debug($FORMATTED, ...)
- pattern: $LOGGER.info($FORMATTED) - pattern: $LOGGER.info($FORMATTED, ...)
- pattern: $LOGGER.warning($FORMATTED) - pattern: $LOGGER.warning($FORMATTED, ...)
- pattern: $LOGGER.error($FORMATTED) - pattern: $LOGGER.error($FORMATTED, ...)
- pattern: $LOGGER.critical($FORMATTED) - pattern: $LOGGER.critical($FORMATTED, ...)
- pattern: $LOGGER.exception($FORMATTED) - pattern: $LOGGER.exception($FORMATTED, ...)
- pattern: $LOGGER.log($LEVEL, $FORMATTED, ...)
- metavariable-pattern: - metavariable-pattern:
metavariable: $LOGGER metavariable: $LOGGER
patterns: patterns:

View File

@ -73,7 +73,7 @@ class Command(BaseCommand):
cnt = 0 cnt = 0
for queue_name in queues: for queue_name in queues:
if not settings.DEVELOPMENT: if not settings.DEVELOPMENT:
logger.info("launching queue worker thread " + queue_name) logger.info("launching queue worker thread %s", queue_name)
cnt += 1 cnt += 1
td = ThreadedWorker(queue_name, logger) td = ThreadedWorker(queue_name, logger)
td.start() td.start()
@ -126,5 +126,5 @@ class ThreadedWorker(threading.Thread):
): ):
scope.set_tag("queue_worker", self.worker.queue_name) scope.set_tag("queue_worker", self.worker.queue_name)
self.worker.setup() self.worker.setup()
logging.debug("starting consuming " + self.worker.queue_name) logging.debug("starting consuming %s", self.worker.queue_name)
self.worker.start() self.worker.start()

View File

@ -189,7 +189,6 @@ class ClientDescriptor:
def finish_current_handler(self) -> bool: def finish_current_handler(self) -> bool:
if self.current_handler_id is not None: if self.current_handler_id is not None:
err_msg = f"Got error finishing handler for queue {self.event_queue.id}"
try: try:
finish_handler( finish_handler(
self.current_handler_id, self.current_handler_id,
@ -198,7 +197,9 @@ class ClientDescriptor:
self.apply_markdown, self.apply_markdown,
) )
except Exception: except Exception:
logging.exception(err_msg, stack_info=True) logging.exception(
"Got error finishing handler for queue %s", self.event_queue.id, stack_info=True
)
finally: finally:
self.disconnect_handler() self.disconnect_handler()
return True return True

View File

@ -44,7 +44,6 @@ def handler_stats_string() -> str:
def finish_handler( def finish_handler(
handler_id: int, event_queue_id: str, contents: List[Dict[str, Any]], apply_markdown: bool handler_id: int, event_queue_id: str, contents: List[Dict[str, Any]], apply_markdown: bool
) -> None: ) -> None:
err_msg = f"Got error finishing handler for queue {event_queue_id}"
try: try:
# We do the import during runtime to avoid cyclic dependency # We do the import during runtime to avoid cyclic dependency
# with zerver.lib.request # with zerver.lib.request
@ -70,14 +69,14 @@ def finish_handler(
request, request,
apply_markdown=apply_markdown, apply_markdown=apply_markdown,
) )
except OSError as e: except Exception as e:
if str(e) != "Stream is closed": if not (
logging.exception(err_msg, stack_info=True) (isinstance(e, OSError) and str(e) == "Stream is closed")
except AssertionError as e: or (isinstance(e, AssertionError) and str(e) == "Request closed")
if str(e) != "Request closed": ):
logging.exception(err_msg, stack_info=True) logging.exception(
except Exception: "Got error finishing handler for queue %s", event_queue_id, stack_info=True
logging.exception(err_msg, stack_info=True) )
class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler): class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):