Package: ses-log-handler
SES log handlerLog messages to email via Amazon SESRate limiting and bouncing are currently not supported.If you are using Django then this is also possible usingDjango's AdminEmailHandleranddjango-seswhich supports rate limiting via AWS_SES_AUTO_THROTTLE.Quick startInstallationpipinstallses-log-handlerIf you using IAM roles to get credentials for AWS or have the correct environment variables defined (seeBoto3 configuration guide) then you can simply set asenderandrecipientsaddresses for the handler:importlogginglogger=logging.getLogger(__name__)ses_handler=SESHandler(sender='from@example.com',recipients=['to@example.com'],)ses_handler.setLevel(logging.ERROR)logger.addHandler(ses_handler)There is an example of how to configure the log hander usingdictConfig()andfileConfig()Note: It is advised you set the log level to eitherCRITICALorERROR. This will stop the reciver_mails from being spammed by logs and you incuring a large SES bill.Configuration optionsIf you want to explicitly set the access, secret and region this can also be when instantiating theSESHandler.It also possible to force the subject line to be the same for each emailmail_handler=SESHandler(sender='from@example.com',recipients=('to@example.com'),access_key='<access-key>',secret_key='<secret-key>',region='<region>',subject='Error: Exception raised',)senderRequired: Who the log email should be sent from. The domain should be added and configured as averified sender domainrecipientsRequired: A list of recipients who should receive the log emails.If your SES account only has "sandbox" access (seeSES dashboard) these email addresses must be added asverified sender email addressaccess_keyOptional: The AWS access key for a user who has access to send emails via SES.It isbest practices for managing AWS access keysuse instance roles instead of passing access keys to your application.If the access_key argument is not provided then the SESHandler (which uses boto3) will fall back to getting credentials from either the instance role or environment variables. See theboto3 credentials guidefor more information.secret_keyOptional: The AWS secret key for a user who has access to send emails via SES.It isbest practices for managing AWS access keysuse instance roles instead of passing access keys to your application.If the access_key argument is not provided then the SESHandler (which uses boto3) will fall back to getting credentials from either the instance role or environment variables. See theboto3 credentials guidefor more information.regionOptional: The AWS region which should be used to send emails via SESBy default the region that your application is running in will be usedsubjectOptional: Force overrides the subject line to be the same for each email.The default is<log_level>: <message>Configuration examplesThe below examples both create a logging config which logs everythingERRORand above to SES and anythingWARNINGand below to the console.Dict configimportloggingLOGGING={'version':1,'disable_existing_loggers':False,'formatters':{'general':{'format':'%(asctime)s%(name)s.%(funcName)s%(levelname)s[%(lineno)d]%(message)s',# NOQA: E501}},'handlers':{'console':{'class':'logging.StreamHandler','formatter':'general','level':'INFO',},'ses':{'class':'ses_log_handler.SESHandler','formatter':'general','level':'ERROR','sender':'from@example.com','recipients':['to@example.com'],},},'root':{'level':'INFO','handlers':['ses','console'],}}logging.config.dictConfig(LOGGING)File config[loggers]keys=root[handlers]keys=sesHandler,consoleHandler[formatters]keys=generalFormatter[logger_root]level=INFOhandlers=sesHandler,consoleHandler[handler_consoleHandler]class=StreamHandlerlevel=INFOformatter=generalFormatterargs=(sys.stdout,)[handler_sesHandler]class=ses_log_handler.SESHandlerlevel=ERRORformatter=generalFormatterargs=['from@example.com', ['to@example.com']][formatter_generalFormatter]format=%(asctime)s %(name)s.%(funcName)s %(levelname)s [%(lineno)d] %(message)sThen to load this config you can useimportlogginglogging.config.fileConfig('logging.conf',disable_existing_loggers=False)