def process_response(self, request, response): # Ignore the static media file requests if settings.MEDIA_URL and request.META['PATH_INFO'].startswith(settings.MEDIA_URL): return response # Only give debug infos to local ips and if debug = true if not settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: return response if not settings.MEDIA_URL: logging.warn('Please set MEDIA_URL to filter out unncessary FirePHP logs.') # Calculate db times time = 0.0 for q in connection.queries: time += float(q['time']) # Generate db times table query_info = [["SQL Statement","Time"]] query_info += [[query['sql'], query['time']] for query in connection.queries] label = "%d SQL queries took %f seconds" % \ (len(connection.queries), time) FirePHPHandler.logs.append(FirePHP.table(query_info, label)) # Set base FirePHP JSON protocol headers headers = FirePHP.base_headers() for key, value in headers: response[key] = value # Translate the JSON message to headers for key, value in FirePHP.generate_headers(FirePHPHandler.logs): response[key] = value return response
def emit(self, record): """ Record all the logs that comes by converting them to JSON notation. """ if record.exc_info: FirePHPHandler.logs.append(FirePHP.exception(record)) else: FirePHPHandler.logs.append(FirePHP.log(record))