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.
Sets whether or not logging is enabled.
Specifies the directory that log files should be stored in. This directory must be writable by the process running Django.
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.
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
"%(asctime)s - %(levelname)s - %(message)s"
The format for lines in the log file. See Python’s
documentation for possible values in the format string.
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.
The minimum level to log. Possible values are
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.
New in version 1.0.17.
Whether to log output to stdout. This would be in addition to any other configured logging, and is intended for environments like Docker.
TimedLogInfo(message, warning_at, critical_at, default_level, log_beginning, request)¶
A utility class created by
log_timedthat 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)¶
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.
RequestLogFormatter(request_fmt, *args, **kwargs)¶
__init__(request_fmt, *args, **kwargs)¶
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_FORMATand 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
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:
Trueif the record can be logged.
Falseif 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)¶
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