My objective is to raise SystemExit and log the error when my program encounter an unexpected behavior.
I was doing something like:
logger.error('Unexpected behaviour')
raise SystemExit
In order to avoid the repetition in my code i tried to write a decorator to raise SystemExit at each logger.error call:
error = logger.error
def error_from_logger(msg) :
''' Decorator for logger.error to kill the program at the call '''
error(msg)
raise SystemExit
logger.error = error_from_logger
del(error_from_logger)
So my question is: Is my decorator pythonic? And if not what is the best pythonic way to write it? (I saw people use @something but I don't understand it's usage).
Thanks!