self self . @record_log ( ) , main, .. , - MyClass - , , MyClass ! ,
@record_log(self.logs)
def test(self, n):
test = record_log(self.logs)(test)
, test __init__, ..
def __init__(self, log_location)
self.logs = logging(log_location)
self.test = record_log(self.logs)(self.test)
, func . , , , ( ).
def record_log(log_object):
def deco(func):
def wrap(*args, **kwargs):
rs = func(*args, **kwargs)
if rs:
log_object.record('success')
else:
log_object.record('fail')
return rs
return wrap
return deco