mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	bugdown: Add bugdown_logger for logging.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							8c2f0f68b2
						
					
				
				
					commit
					a7e913894c
				
			@@ -81,6 +81,8 @@ STREAM_LINK_REGEX = r"""
 | 
				
			|||||||
                     \*\*                         # ends by double asterisks
 | 
					                     \*\*                         # ends by double asterisks
 | 
				
			||||||
                    """
 | 
					                    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bugdown_logger = logging.getLogger()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def rewrite_local_links_to_relative(link: str) -> str:
 | 
					def rewrite_local_links_to_relative(link: str) -> str:
 | 
				
			||||||
    """ If the link points to a local destination we can just switch to that
 | 
					    """ If the link points to a local destination we can just switch to that
 | 
				
			||||||
    instead of opening a new tab. """
 | 
					    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)
 | 
					            tweet = timeout(3, api.GetStatus, tweet_id)
 | 
				
			||||||
            res = tweet.AsDict()
 | 
					            res = tweet.AsDict()
 | 
				
			||||||
        except AttributeError:
 | 
					        except AttributeError:
 | 
				
			||||||
            logging.error('Unable to load twitter api, you may have the wrong '
 | 
					            bugdown_logger.error('Unable to load twitter api, you may have the wrong '
 | 
				
			||||||
                          'library installed, see https://github.com/zulip/zulip/issues/86')
 | 
					                                 'library installed, see https://github.com/zulip/zulip/issues/86')
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
        except TimeoutExpired:
 | 
					        except TimeoutExpired:
 | 
				
			||||||
            # We'd like to try again later and not cache the bad result,
 | 
					            # 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
 | 
					                # but for now it seems reasonable to log at error
 | 
				
			||||||
                # level (so that we get notified), but then cache the
 | 
					                # level (so that we get notified), but then cache the
 | 
				
			||||||
                # failure to proceed with our usual work
 | 
					                # failure to proceed with our usual work
 | 
				
			||||||
                logging.error(traceback.format_exc())
 | 
					                bugdown_logger.error(traceback.format_exc())
 | 
				
			||||||
                return None
 | 
					                return None
 | 
				
			||||||
    return res
 | 
					    return res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -741,7 +743,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
 | 
				
			|||||||
            # We put this in its own try-except because it requires external
 | 
					            # We put this in its own try-except because it requires external
 | 
				
			||||||
            # connectivity. If Twitter flakes out, we don't want to not-render
 | 
					            # connectivity. If Twitter flakes out, we don't want to not-render
 | 
				
			||||||
            # the entire message; we just want to not show the Twitter preview.
 | 
					            # 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
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_url_data(self, e: Element) -> Optional[Tuple[str, str]]:
 | 
					    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
 | 
					    order to prevent AdminNotifyHandler from sending the santized
 | 
				
			||||||
    original markdown formatting into another Zulip message, which
 | 
					    original markdown formatting into another Zulip message, which
 | 
				
			||||||
    could cause an infinite exception loop."""
 | 
					    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]:
 | 
					def get_email_info(realm_id: int, emails: Set[str]) -> Dict[str, FullNameInfo]:
 | 
				
			||||||
    if not emails:
 | 
					    if not emails:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -642,7 +642,7 @@ class ZulipTestCase(TestCase):
 | 
				
			|||||||
        with \
 | 
					        with \
 | 
				
			||||||
                self.settings(ERROR_BOT=None), \
 | 
					                self.settings(ERROR_BOT=None), \
 | 
				
			||||||
                mock.patch('zerver.lib.bugdown.timeout', side_effect=KeyError('foo')), \
 | 
					                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
 | 
					            yield
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_default_device(self, user_profile: UserProfile,
 | 
					    def create_default_device(self, user_profile: UserProfile,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user