I am using the handlers TimeRotatingFileHandler and the SMTPHandler. I want to send the INFO messages to the file log and the exceptions the email. My setup is below:
import logging
from logging.handlers import TimeRotatingFileHandler
from logging.handlers import SMTPHandler
filelog_handler = TimedRotatingFileHandler(output_file, when='midnight')
filelog_handler.setFormatter(log_formatter)
filelog_handler.setLevel(logging.DEBUG)
logger.addHandler(filelog_handler)
maillog_handler = SMTPHandler(mailhost=("email.address.org", 25),
fromaddr="email@address.org",
toaddrs="email@address.org",
subject="send_err_email.py Message")
maillog_handler.setLevel(logging.INFO)
logger.addHandler(mail_log)
When I try this code it either sends to both file and email or it sends nothing. Can anyone help me pin point what I am doing wrong or if this is even possible. Your help is greatly appreciated.