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_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"
.
LOGGING_BLACKLIST¶
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.
-
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
(record)[source]¶ 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.
-
format_request
(request)[source]¶ 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.
-
__init__
(names)[source]¶ Initialize the filter.
Parameters: names (list of unicode) – A list of logger names. Each logger (and their children) will be excluded from the logs.
-
filter
(record)[source]¶ 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
-
-
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 thecritical_at
parameters.