I have currently using logging which sends any error to email.
#EMAIL AN ERROR
logging.getLogger('googleapiclient.discovery').setLevel(logging.WARNING)
smtp_handler = logging.handlers.SMTPHandler(mailhost=(config.EMAIL_HOST, config.EMAIL_PORT),
fromaddr=config.EMAIL_FROM,
toaddrs=config.EMAIL_TO,
subject=config.EMAIL_SUBJECT)
logger = logging.getLogger()
logger.addHandler(smtp_handler)
What is the clean way to add an extra logging section with will save all messages
logger.info("SAMPLE")
to the log file which will be in the same folder as python scripts?
This is basicConfig which I have trying to use, but not sure how to combine Logging errors to email and logger.info() save to file?
#LOGGING TO THE FILE
logging.basicConfig(filename=config.LOG_FILE,
filemode='w',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt='%H:%M:%S',
level=logging.INFO)
I'm looking for:
1) All logger.info() will be saved to the file BUT NOT EMAILED.
2) Warnings + will be sent to the email address as well as saved to the file