Skip to content

Instantly share code, notes, and snippets.

@capttwinky
Created April 7, 2014 18:42
Show Gist options
  • Save capttwinky/10028506 to your computer and use it in GitHub Desktop.
Save capttwinky/10028506 to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
from functools import wraps
class dummy_statsd_connection(object):
def __init__(self, *args, **kwargs):
self.data = []
self.log_data(args, kwargs)
def log_data(self, *args, **kwargs):
self.data.append({'args':args, 'kwargs':kwargs})
def __enter__(self):
return self.log_data
def __exit__(self, *args, **kwargs):
print self.data
def wrap_with_statsd(fn_in):
@wraps(fn_in)
def inner_fn(*args, **kwargs):
global statsd
with dummy_statsd_connection() as statsd:
mret = fn_in(*args, **kwargs)
return mret
return inner_fn
@wrap_with_statsd
def do_some_thing(mything1, mything2):
statsd(mything1)
print mything2
def main():
print do_some_thing('tologs', 'notlogs')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment