Skip to content

Instantly share code, notes, and snippets.

@saurabh-hirani
Created June 9, 2013 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabh-hirani/5737743 to your computer and use it in GitHub Desktop.
Save saurabh-hirani/5737743 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import inspect
from functools import wraps
def get_line_number():
# inspect the current frame, go back 2 frames and get the line number.
return inspect.currentframe().f_back.f_back.f_lineno
def log_decorator(loglevel):
def log_decorator_creator(func):
@wraps(func)
def wrapper_around_func(*args):
print func.__name__,
if (loglevel == 'debug'):
print " called_from_line:" + str(get_line_number()),
print " args - [" + ", ".join(args) + "]"
return wrapper_around_func
return log_decorator_creator
@log_decorator('info')
def func1(arg1, arg2):
print "entering func1"
@log_decorator('debug')
def func2(arg1, arg2):
print "entering func2"
func1('this', 'that')
func2('who', 'what')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment