Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
new path; flush logs; python2
  • 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') logger = logging.getLogger('instrumentation')
handler = logging.FileHandler('/tmp/foo.log') handler = logging.FileHandler('/var/tmp/instrument.log')
formatter = logging.Formatter('%(message)s') formatter = logging.Formatter('%(message)s')
handler.setFormatter(formatter) handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(handler)
Expand All @@ -20,12 +20,13 @@ def instrument_function(obj):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
result = obj(*args, **kwargs) result = obj(*args, **kwargs)
logger.debug('called {function} from module {module} with args {args}, {kwargs} returned {result}'.format( logger.debug('called {function} from module {module} with args {args}, {kwargs} returned {result}'.format(
function=obj.__qualname__, function=obj.__name__,
module=obj.__module__, module=obj.__module__,
args=args, args=args,
kwargs=kwargs, kwargs=kwargs,
result=result result=result
)) ))
handler.flush()
return result return result
return wrapper return wrapper


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

0 comments on commit 65abd7f

Please sign in to comment.