djblets.log.middleware¶
Middleware used for logging.
The middleware sets up some advanced logging capabilities for profiling and exception logging.
- class CursorDebugWrapper(cursor, db)¶
Bases:
CursorDebugWrapper
Debug cursor for databases that stores tracebacks in query logs.
This is a replacement for the default debug wrapper for database cursors which stores a traceback in
connection.queries
.This will dramatically increase the overhead of having
settings.DEBUG=True
, so use with caution.- execute(*args, **kwargs)¶
Execute a SQL statement.
This will record an entry in the query log and attach a stack trace.
- executemany(*args, **kwargs)¶
Execute multiple SQL statements.
This will record an entry in the query log and attach a stack trace.
Note that the Django ORM does not appear to actually make use of this method. Third-parties can still use it.
- reformat_sql(sql)¶
- class LoggingMiddleware(get_response)¶
Bases:
MiddlewareMixin
A piece of middleware that sets up page timing and profile logging.
This is needed if using
settings.LOGGING_PAGE_TIMES
orsettings.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'>)¶
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)¶
Processes an incoming request. This will set up logging.
- process_view(request, callback, callback_args, callback_kwargs)¶
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)¶
Handler for processing a response. Dumps the profiling information to the profile log file.
- process_exception(request, exception)¶
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.
- __annotations__ = {}¶