if python is run in debug mode (the normal mode)every time the discounted_price(function is called log message will be added to the file logged log in the machine' local temporary directoryas this log file extract illustratescalleddiscounted_price( - calleddiscounted_price( - calleddiscounted_price( make_integer=true- calleddiscounted_price( true- calleddiscounted_price( - invalid price if python is run in optimized mode (using the - command-line option or if the pythonoptimize environment variable is set to - )then no logging will take place here' the code for setting up logging and for the decoratorif __debug__logger logging getlogger("logger"logger setlevel(logging debughandler logging filehandler(os path jointempfile gettempdir()"logged log")logger addhandler(handlerdef logged(function)@functools wraps(functiondef wrapper(*args**kwargs)log "calledfunction __name__ "(log +"join(["{ ! }format(afor in args["{ ! }={ ! }format(kvfor kv in kwargs items()]result exception none tryresult function(*args**kwargsreturn result except exception as errexception err finallylog +(("-str(result)if exception is none else "{ }{ }format(type(exception)exception)logger debug(logif exception is not noneraise exception return wrapper elsedef logged(function)return function