Jump to >

This documentation covers Djblets 2.0. You can see the latest Djblets documentation or all other versions.


Logging support.

This can be used to offer some advanced logging capabilities.

Note that this predates Django’s modern logging support, and is here primarily for compatibility.


The following settings control logging.


Default: False

Sets whether or not logging is enabled.


Default: None

Specifies the directory that log files should be stored in. This directory must be writable by the process running Django.


Default: None

The name of the log files, excluding the extension and path. This will usually be the name of the website or web application. The file extension will be automatically appended when the file is written.


Default: False

Specifies whether or not code profiling is allowed. If True, visiting any page with a ?profiling=1 parameter in the URL will cause the request to be profiled and stored in a .prof file using the defined LOGGING_DIRECTORY and LOGGING_NAME.


Default: "%(asctime)s - %(levelname)s - %(message)s"

The format for lines in the log file. See Python’s logging documentation for possible values in the format string.


Default: False

If enabled, page access times will be logged. Specifically, it will log the initial request, the finished render and response, and the total time it look.

The username and page URL will be included in the logs.


Default: "DEBUG"

The minimum level to log. Possible values are "DEBUG", "INFO", "WARNING", "ERROR" and "CRITICAL".


Default: ['django.db.backends']

A list of logger names to exclude from the logs. Each logger with the given name will be filtered out, along with any descendents of those loggers.

class TimedLogInfo(message, warning_at, critical_at, default_level, log_beginning, request)[source]

Bases: object

A utility class created by log_timed that handles the timed logging functionality and provides a way to end the timed logging operation.

__init__(message, warning_at, critical_at, default_level, log_beginning, request)[source]

x.__init__(…) initializes x; see help(type(x)) for signature


Stops the timed logging operation. The resulting time of the operation will be written to the log file. The log level depends on how long the operation takes.

class RequestLogFormatter(request_fmt, *args, **kwargs)[source]

Bases: logging.Formatter

__init__(request_fmt, *args, **kwargs)[source]

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument (if omitted, you get the ISO8601 format).


Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.


Return formatted request information for the log message.

The returned string will be based off the configured settings.LOGGING_REQUEST_FORMAT and keys in the request, if found.

If anything from the request is missing, an empty string will be returned.

Parameters:request (django.http.HttpRequest) – The HTTP request from the client.
Returns:The request-specific string to include in the log message. This may be empty.
Return type:unicode
class BlacklistFilter(names)[source]

Bases: logging.Filter

Blacklists the provided loggers (and their children) from logging.


Initialize the filter.

Parameters:names (list of unicode) – A list of logger names. Each logger (and their children) will be excluded from the logs.

Return whether this record should be logged.

The record is only logged if it’s not in the list of any of the loggers on the blacklist, and if it doesn’t have a parent logger listed.

Parameters:record (logging.LogRecord) – The record to filter.
Returns:True if the record can be logged. False if it must be ignored.
Return type:bool

Sets up the main loggers, if they haven’t already been set up.


Sets up the profiling logger, if it hasn’t already been set up.


Restarts the logging. The next page view will set up the loggers based on any new settings.

log_timed(message, warning_at=5, critical_at=15, log_beginning=True, default_level=10, request=None)[source]

Times an operation, displaying a log message before and after the operation. The log level for the final log message containing the operation runtime will be based on the runtime, the warning_at and the critical_at parameters.