Commit af69e2fd authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

add option for emailing full log in body

parent 2c0024ba
......@@ -32,6 +32,10 @@ def __exit_handler(logger, notify):
else:
addresses = list(set(addresses))
logger.email_log(addresses)
elif 'DEBUG' in notify and notify['DEBUG']:
addresses = list(set(notify['DEBUG']))
logging.info('Sending full DEBUG email to addresses: %s', ', '.join(addresses))
logger.email_log(addresses)
else:
logging.info('No errors found. Email not sent')
......@@ -132,12 +136,18 @@ class OperationalLogger:
"""Return whether any CRITICAL-level log statements in buffer."""
return len(self.__critical_buffer.getvalue()) > 0
def email_log(self, addresses, from_address=None):
def email_log(self, addresses, from_address=None, level=logging.ERROR):
"""Send email to addresses with current buffered errors."""
if from_address is None:
from_address = self.__from_address
logging.info("Sending log email to %s", addresses)
message = "<br />\n".join([self.__class__.__colorize(line) for line in self.__error_buffer.getvalue().split('\n')])
if level == logging.CRITICAL:
buf = self.__critical_buffer.getvalue()
elif level == logging.DEBUG:
buf = self.__debug_buffer.getvalue()
else:
buf = self.__error_buffer.getvalue()
message = "<br />\n".join([self.__class__.__colorize(line) for line in buf.split('\n')])
OperationalMail.send_status(subject='Errors detected {}:{}'.format(self.__server_name,
os.path.basename(sys.argv[0])),
message=message, to_list=addresses, from_address=from_address,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment