P
pstatham
I'm trying to use pythons logging.handlers.SMTPHandler with a
configuration file (so that I don't have to have passwords etc. inside
of the script)
Now the guide I'm following is here, now the
RotatingFileHandler is working, but I never receive an email, or an
error for the SMTPHandler.
Anyway here's the python code
import logging
import logging.config
logDir = "./logs/"
logging.config.fileConfig(logDir+'logging.conf')
logging.getLogger('email')
logging.debug('THIS IS A DEBUG MESSAGE')
logging.error('THIS IS AN ERROR')
And here's the config file
[loggers]
keys=root,email
[logger_root]
level=DEBUG
handlers=rotatingFileHandler
[logger_email]
level=ERROR
handlers=email
qualname=email
[formatters]
keys=emailFormatter,rotatingFormatter
[formatter_emailFormatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
[formatter_rotatingFormatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
datefmt=%m-%d %H:%M
[handlers]
keys=email,rotatingFileHandler
[handler_email]
class=handlers.SMTPHandler
level=ERROR
formatter=emailFormatter
args=('mail.xx.cocom','(e-mail address removed)',['(e-mail address removed)',],'ERROR!',
('user','passwd'))
[handler_rotatingFileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=rotatingFormatter
args=('./logs/log.out', 'maxBytes=1000000', 'backupCount=5')
Because I wasn't getting an error I decided to temporarily add some
print statements into .\Lib\logging\handlers.py, In SMTPHandler
__init__ I print out mailhost, from, to etc. And these are all
correct. I then inserted a few print statements into the different
levels of emit to see which branch of the logic it was following. None
of the print statements print. Which leads me to believe emit() is
never being called and therefore the email never gets sent.
So what am I doing wrong?
configuration file (so that I don't have to have passwords etc. inside
of the script)
Now the guide I'm following is here, now the
RotatingFileHandler is working, but I never receive an email, or an
error for the SMTPHandler.
Anyway here's the python code
import logging
import logging.config
logDir = "./logs/"
logging.config.fileConfig(logDir+'logging.conf')
logging.getLogger('email')
logging.debug('THIS IS A DEBUG MESSAGE')
logging.error('THIS IS AN ERROR')
And here's the config file
[loggers]
keys=root,email
[logger_root]
level=DEBUG
handlers=rotatingFileHandler
[logger_email]
level=ERROR
handlers=email
qualname=email
[formatters]
keys=emailFormatter,rotatingFormatter
[formatter_emailFormatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
[formatter_rotatingFormatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
datefmt=%m-%d %H:%M
[handlers]
keys=email,rotatingFileHandler
[handler_email]
class=handlers.SMTPHandler
level=ERROR
formatter=emailFormatter
args=('mail.xx.cocom','(e-mail address removed)',['(e-mail address removed)',],'ERROR!',
('user','passwd'))
[handler_rotatingFileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=rotatingFormatter
args=('./logs/log.out', 'maxBytes=1000000', 'backupCount=5')
Because I wasn't getting an error I decided to temporarily add some
print statements into .\Lib\logging\handlers.py, In SMTPHandler
__init__ I print out mailhost, from, to etc. And these are all
correct. I then inserted a few print statements into the different
levels of emit to see which branch of the logic it was following. None
of the print statements print. Which leads me to believe emit() is
never being called and therefore the email never gets sent.
So what am I doing wrong?