I am using one central LogUtil module for all my python modules:
host = 'localhost'
MAILHOST = 'mycompany-com.mail.protection.outlook.com'
FROM = 'me@me.com'
TO = ['me@me.com', you@you.com']
SUBJECT = 'Python Error Logging'
env = None
logger = logging.getLogger(__name__)
formatter = logging.Formatter('%(asctime)s, %(levelname)-5.5s [%(name)s] %(message)s')
class BufferingSMTPHandler(logging.handlers.BufferingHandler):
#my code
....
consoleHandler = logging.StreamHandler(sys.stdout,)
consoleHandler.setFormatter(formatter)
logger.addHandler(consoleHandler)
emailHandler = BufferingSMTPHandler(MAILHOST, FROM, TO, SUBJECT, 10)
emailHandler.setLevel(logging.ERROR)
logger.addHandler(emailHandler)
rollbar.init('c6688cfac689497ba8dc0b970f118f5d', 'production')
rollbar_handler = RollbarHandler()
rollbar_handler.setLevel(logging.WARNING)
logger.addHandler(rollbar_handler)
logger.setLevel(logging.DEBUG)
logger.propagate = False
this LogUtil sends an email and posts to rollbar the error messages. My tests also import this LogUtil module, and all the errors are being emailed and send to rollbar. To avoid rollbars and emails from tests, what is the best and most efficient way to config my logging?
for example; is it a good practice to use an adapted logging if the file that calls Logutil has "test" in its name. Should I work with config file for this case? ... A good example is welcome !
I am using python 2.7.9
Aucun commentaire:
Enregistrer un commentaire