def log_api_warning_message_to_browser_console(message): """Log an API warning message to the browser's console.""" try: import chromelogger chromelogger.warn('%cAPI Server Warning:', 'color: DarkOrange; font-weight: bold', message) except Exception: pass # Failures here should not prevent the API error response
def log_api_exception_to_browser_console(sender, exception, **extra): """Log an API exception to the browser's console.""" if sender.debug and sender.config.get('API_LOG_EXCEPTIONS_TO_BROWSER_CONSOLE'): try: import chromelogger type_, value_, traceback_ = sys.exc_info() tbs = traceback.extract_tb(traceback_) exc_only = traceback.format_exception_only(type_, value_) group_func = chromelogger.group_collapsed chromelogger.group_collapsed("%cAPI Server Error:", 'color: red;', str(exc_only[-1])) chromelogger.log('Traceback (most recent call last):') for i, tb in enumerate(tbs): if i == len(tbs) - 1: group_func = chromelogger.group # Expand the last stack frame group_func('%cFile "%s", line %i, in %s', 'font-weight: normal;', tb[0], tb[1], tb[2]) chromelogger.log(tb[3]) chromelogger.group_end() chromelogger.warn(''.join(exc_only)) chromelogger.group_end() except Exception: pass # Failures here should not prevent the API error response