AdminEmailHandler
An exception log handler that emails log entries to site admins.
If the request is passed as the first argument to the log record, request data will be provided in the email report.
Attributes
| Attribute | Type | Description |
|---|---|---|
| include_html | boolean = False | Boolean flag that determines whether to include an HTML version of the exception traceback in the email report. |
| email_backend | string = None | The Python path to the email backend class to use for sending emails, deprecated in favor of the 'using' attribute. |
| using | string = None | The name of the mailer alias defined in settings to use for sending admin emails. |
| reporter_class | string = settings.DEFAULT_EXCEPTION_REPORTER | The exception reporter class used to generate the text and HTML bodies of the error notification email. |
Constructor
Signature
def AdminEmailHandler(
include_html: boolean = False,
email_backend: str = None,
reporter_class: str = None,
using: str = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| include_html | boolean = False | Whether to include an HTML attachment containing a full traceback in the email. |
| email_backend | str = None | The Python path to a specific email backend class to use (deprecated). |
| reporter_class | str = None | The Python path to the exception reporter class to use for generating the email body. |
| using | str = None | The name of the mailer alias to use for sending emails. |
Methods
emit()
@classmethod
def emit(
record: LogRecord
) - > null
Processes a log record by generating an email report and sending it to site administrators. It extracts request metadata, formats the traceback using the configured reporter class, and handles both plain text and optional HTML content.
Parameters
| Name | Type | Description |
|---|---|---|
| record | LogRecord | The logging record object containing the message, level, and optional request or exception information to be emailed. |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the method performs an I/O operation by sending an email. |
send_mail()
@classmethod
def send_mail(
subject: string,
message: string,
*args: any,
**kwargs: any
) - > null
Sends the formatted log entry to the administrators defined in the project settings. It utilizes the configured email backend or mailer alias to dispatch the message.
Parameters
| Name | Type | Description |
|---|---|---|
| subject | string | The summary line for the email, typically containing the log level and source IP. |
| message | string | The plain text body of the email containing the log message and traceback. |
| *args | any | Additional positional arguments passed to the underlying mail delivery function. |
| **kwargs | any | Additional keyword arguments, such as 'html_message', used to customize the email delivery. |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the method triggers the mail delivery process. |
format_subject()
@classmethod
def format_subject(
subject: string
) - > string
Escape CR and LF characters.
Parameters
| Name | Type | Description |
|---|---|---|
| subject | string | The raw subject string that may contain prohibited newline characters. |
Returns
| Type | Description |
|---|---|
string | The sanitized subject string with newline and carriage return characters replaced by literal escape sequences. |