def handle_search_signal(sender, **kwargs): """ catches the search signal sent from the flask-solrquery extension, extracts some event data and sends it to the appropriate logger. TODO: figure out a way to push the logic of which event stream (e.g., 'api' or 'search') should handle the event out of here and into the actual blueprints. I tried and failed to come up with a solution. """ resp = kwargs.pop('response') # common search event data log_data = { 'q': resp.get_query(), 'hits': resp.get_hits(), 'count': resp.get_count(), 'start': resp.get_start_count(), 'qtime': resp.get_qtime(), 'results': resp.get_doc_values('bibcode', 0, config.SEARCH_DEFAULT_ROWS), 'error_msg': resp.get_error_message(), 'http_status': resp.get_http_status(), 'solr_url': resp.request.url, } if hasattr(g, 'api_user'): log_data['dev_key'] = g.api_user.get_dev_key() log_event('api', **log_data) elif hasattr(g, 'user_cookie_id'): log_data['user_cookie_id'] = g.user_cookie_id log_event('search', **log_data)
def solrquery_exception(error): msg = "Search service error: %s" % error dev_key = hasattr(g, 'api_user') and g.api_user.get_dev_key() or None exc_info = error.exc_info exc_str = traceback.format_exception(*exc_info) current_app.logger.error("%s: (%s, %s) %s" % (msg, exc_info[0], exc_info[1], exc_info[2])) log_event('api', msg=msg, dev_key=dev_key, exception=exc_str) return {'error': msg},500,None
def solrquery_exception(error): msg = "Search service error: %s" % error user_cookie_id = hasattr(g, 'user_cookie_id') and g.user_cookie_id or None exc_info = error.exc_info exc_str = traceback.format_exception(*exc_info) current_app.logger.error("%s: (%s, %s) %s" % (msg, exc_info[0], exc_info[1], exc_info[2])) log_event('search', msg=msg, user_cookie_id=user_cookie_id, exception=exc_str) flash(msg, 'error') abort(500)