1353
1354
1355async def callback_monitor(context: ContextTypes.DEFAULT_TYPE):
1356 logger.debug(f"EXECUTOR pending work items: {len(EXECUTOR._pending_work_items)} tasks remain")1357 EXECUTOR_TASKS_REMAINING.set(len(EXECUTOR._pending_work_items))
1358
1359
640 logger.debug(f"Update {update} caused ChatMigrated error: {context.error}")
641 except TelegramError:
642 # handle all other telegram related errors
643 logger.debug(f"Update {update} caused TelegramError error: {context.error}") 644
645
646def init_chat_data(chat_data, mode="dl", flood=True):
637 logger.debug(f"Update {update} caused NetworkError error: {context.error}")
638 except ChatMigrated as e:
639 # the chat_id of a group has changed, use e.new_chat_id instead
640 logger.debug(f"Update {update} caused ChatMigrated error: {context.error}") 641 except TelegramError:
642 # handle all other telegram related errors
643 logger.debug(f"Update {update} caused TelegramError error: {context.error}")
684 # If message just some text passed (not isinstance(message, Message)):
685 # all_links = find_all_links(message, default_scheme="http")
686 # urls = [link for link in all_links if url_valid_and_allowed(link)]
687 logger.info(f"prepare_urls: urls list: {urls}") 688
689 urls_dict = {}
690 for url_item in urls:
631 logger.debug(f"Update {update} caused BadRequest error: {context.error}")
632 except TimedOut:
633 # handle slow connection problems
634 logger.debug(f"Update {update} caused TimedOut error: {context.error}") 635 except NetworkError:
636 # handle other connection problems
637 logger.debug(f"Update {update} caused NetworkError error: {context.error}")
Formatting the message manually before passing it to a logging
call does unnecessary work if logging is disabled. Consider using the logging
module's built-in formatting features to avoid that.
If your logging level is set to "WARNING"
, but the logging call is:
logging.debug("Data: %s", data)
In the above example, there will be no logging as the level debug
is below warning
. The conversion of the data
object to a string will be skipped by the logging module resulting in improved performance.
logging.debug(f"Data: {data}")
In the code shown above, the conversion of the data
object to a string will happen regardless of whether the message is logged or not (which is based on the log level).
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug(f"Entered function {inspect.stack[0][3]}"))
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug("Entered function %s", inspect.stack[0][3])