如何包含日志记录事件级别 SMTPHandler 主题行?
How to include the logging event level SMTPHandler subject line?
SMTPHandler 要求在 it is initialized 时包含 "subject"。
主题行如何包含生成电子邮件的事件级别?例如:
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')
如何使 logs.info('Info Test')
的主题列表为 INFO: class_name
和 logs.Error('Error Test')
的主题列表为 ERROR: class_name
?
为此,您需要子类化 SMTPHandler
并覆盖 getSubject
method,它表示:
If you want to specify a subject line which is record-dependent, override this method.
SMTPHandler 要求在 it is initialized 时包含 "subject"。
主题行如何包含生成电子邮件的事件级别?例如:
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')
如何使 logs.info('Info Test')
的主题列表为 INFO: class_name
和 logs.Error('Error Test')
的主题列表为 ERROR: class_name
?
为此,您需要子类化 SMTPHandler
并覆盖 getSubject
method,它表示:
If you want to specify a subject line which is record-dependent, override this method.