diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index ef7de8d309..d30feec0a4 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -81,6 +81,8 @@ STREAM_LINK_REGEX = r""" \*\* # ends by double asterisks """ +bugdown_logger = logging.getLogger() + def rewrite_local_links_to_relative(link: str) -> str: """ If the link points to a local destination we can just switch to that instead of opening a new tab. """ @@ -308,8 +310,8 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]: tweet = timeout(3, api.GetStatus, tweet_id) res = tweet.AsDict() except AttributeError: - logging.error('Unable to load twitter api, you may have the wrong ' - 'library installed, see https://github.com/zulip/zulip/issues/86') + bugdown_logger.error('Unable to load twitter api, you may have the wrong ' + 'library installed, see https://github.com/zulip/zulip/issues/86') return None except TimeoutExpired: # We'd like to try again later and not cache the bad result, @@ -334,7 +336,7 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]: # but for now it seems reasonable to log at error # level (so that we get notified), but then cache the # failure to proceed with our usual work - logging.error(traceback.format_exc()) + bugdown_logger.error(traceback.format_exc()) return None return res @@ -741,7 +743,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor): # We put this in its own try-except because it requires external # connectivity. If Twitter flakes out, we don't want to not-render # the entire message; we just want to not show the Twitter preview. - logging.warning(traceback.format_exc()) + bugdown_logger.warning(traceback.format_exc()) return None def get_url_data(self, e: Element) -> Optional[Tuple[str, str]]: @@ -1747,7 +1749,7 @@ def log_bugdown_error(msg: str) -> None: order to prevent AdminNotifyHandler from sending the santized original markdown formatting into another Zulip message, which could cause an infinite exception loop.""" - logging.getLogger('').error(msg) + bugdown_logger.error(msg) def get_email_info(realm_id: int, emails: Set[str]) -> Dict[str, FullNameInfo]: if not emails: diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index bb5c6c2e07..3ddeed3231 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -642,7 +642,7 @@ class ZulipTestCase(TestCase): with \ self.settings(ERROR_BOT=None), \ mock.patch('zerver.lib.bugdown.timeout', side_effect=KeyError('foo')), \ - mock.patch('zerver.lib.bugdown.log_bugdown_error'): + mock.patch('zerver.lib.bugdown.bugdown_logger'): yield def create_default_device(self, user_profile: UserProfile,