0

The SMTPHandler requires a "subject" to be included when it is initialized.

How can the subject line include the level of the event that generated the email? For example:

import logging from logging.handlers import SMTPHandler logger = logging.getLogger('test_logger') email = SMTPHandler(*credentials, subject="class_name") logger.addHandler(email) logs.info('Info Test') logs.error('Error Test') 

How to make the subject list for logs.info('Info Test') be INFO: class_name and logs.Error('Error Test') be ERROR: class_name?

2

1 Answer 1

2

To do this, you need to subclass SMTPHandler and override the getSubject method, which says:

If you want to specify a subject line which is record-dependent, override this method.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.