Skip to content

Commit

Permalink
new path; flush logs; python2
Browse files Browse the repository at this point in the history
  • Loading branch information
stnbu committed Sep 29, 2018
1 parent 674dd48 commit 65abd7f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions instrument.py
Expand Up @@ -7,7 +7,7 @@


logger = logging.getLogger('instrumentation')
handler = logging.FileHandler('/tmp/foo.log')
handler = logging.FileHandler('/var/tmp/instrument.log')
formatter = logging.Formatter('%(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
Expand All @@ -20,12 +20,13 @@ def instrument_function(obj):
def wrapper(*args, **kwargs):
result = obj(*args, **kwargs)
logger.debug('called {function} from module {module} with args {args}, {kwargs} returned {result}'.format(
function=obj.__qualname__,
function=obj.__name__,
module=obj.__module__,
args=args,
kwargs=kwargs,
result=result
))
handler.flush()
return result
return wrapper

Expand All @@ -45,6 +46,8 @@ def instrument_this_module():
"""
frame = inspect.stack()[1]
module = inspect.getmodule(frame[0])
logger.debug('instrumenting module {}'.format(module.__name__))
handler.flush()
# monkeypatch the module...
for name, obj in module.__dict__.items():
if isinstance(obj, types.FunctionType):
Expand Down

0 comments on commit 65abd7f

Please sign in to comment.