Jump to >

djblets.log.middleware

Middleware used for logging.

The middleware sets up some advanced logging capabilities for profiling and exception logging.

class CursorDebugWrapper(cursor, db)[source]

Bases: django.db.backends.util.CursorDebugWrapper

Replacement for CursorDebugWrapper which stores a traceback in connection.queries. This will dramatically increase the overhead of having DEBUG=True, so use with caution.

execute(sql, params=())[source]
reformat_sql(sql)[source]
class LoggingMiddleware[source]

Bases: object

A piece of middleware that sets up page timing and profile logging.

This is needed if using settings.LOGGING_PAGE_TIMES or settings.LOGGING_ALLOW_PROFILING, in order to handle additional logging for page times and detailed profiling for debugging.

ignored_exceptions = (<class ‘django.http.response.Http404’>, <class ‘django.core.exceptions.PermissionDenied’>, <class ‘django.core.exceptions.SuspiciousOperation’>)[source]

Exceptions that should be ignored by this logger.

Each of these are handled by Django itself on the HTTP layer. We don’t want to do any extra/unwanted logging of these.

process_request(request)[source]

Processes an incoming request. This will set up logging.

process_view(request, callback, callback_args, callback_kwargs)[source]

Handler for processing a view. This will run the profiler on the view if profiling is allowed in the settings and the user specified the profiling parameter on the URL.

process_response(request, response)[source]

Handler for processing a response. Dumps the profiling information to the profile log file.

process_exception(request, exception)[source]

Handle exceptions raised on a page.

Logs the exception, along with the username and path where the exception occurred.

Exceptions normally handled by Django’s HTTP layer will be ignored. This helps avoid extraneous logging for 404 and Permission Denied errors.

Parameters:
  • request (django.http.HttpRequest) – The HTTP request for the page.
  • exception (Exception) – The exception that was raised.