Last active
April 1, 2016 15:36
-
-
Save jxinging/47c034fba8efc715081319d55046739e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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