Jump to >

djblets.log

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.

Settings

The following settings control logging.

LOGGING_ENABLED

Default: False

Sets whether or not logging is enabled.

LOGGING_DIRECTORY

Default: None

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

LOGGING_NAME

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.

LOGGING_ALLOW_PROFILING

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.

LOGGING_LINE_FORMAT

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.

LOGGING_PAGE_TIMES

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.

LOGGING_LEVEL

Default: "DEBUG"

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

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]
done()[source]

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]
format(record)[source]
format_request(request)[source]
init_logging()[source]

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

init_profile_logger()[source]

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

restart_logging()[source]

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.