def logged(level, name=None, message=None):
 def decorate(func):
  logname = (name if name else func.__module__)
  log = logging.getLogger(logname)
  logmsg = (message if message else func.__name__)
  @wraps(func)
  def wrapper(*args, **kwargs):
   log.log(level, logmsg)
   return func(*args, **kwargs)
  return wrapper
 return decorate

def logged ( level , name = None , message = None ) : def decorate ( func ) : logname = ( name if name else func . __module__ ) log = logging . getLogger ( logname ) logmsg = ( message if message else func . __name__ ) @ wraps ( func ) def wrapper ( * args , ** kwargs ) : log . log ( level , logmsg ) return func ( * args , ** kwargs ) return wrapper return decorate
add logging to a function .