Skip to content

Instantly share code, notes, and snippets.

@jxinging
Last active April 1, 2016 15:36
Show Gist options
  • Save jxinging/47c034fba8efc715081319d55046739e to your computer and use it in GitHub Desktop.
Save jxinging/47c034fba8efc715081319d55046739e to your computer and use it in GitHub Desktop.
#coding: utf8
from functools import wraps
class logit(object):
def __init__(self, logfile='out.log'):
self.logfile = logfile
def __call__(self, func):
@wraps(func)
def wrapped_function(*args, **kwargs):
log_string = func.__name__ + " was called"
print(log_string)
# Open the logfile and append
with open(self.logfile, 'a') as opened_file:
# Now we log to the specified logfile
opened_file.write(log_string + '\n')
self.notify()
return func(*args, **kwargs)
return wrapped_function
def notify(self):
# logit only logs, no more
pass
@logit()
def myfunc1():
pass
myfunc1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment