Skip to content

Instantly share code, notes, and snippets.

@c7h c7h/gist:4730089
Created Feb 7, 2013

What would you like to do?
primitive debugging class as Singleton
Created on Feb 6, 2013
@author: Christoph Gerneth
import time
import inspect
class SingletonType(type):
def __call__(self, *args, **kwargs):
return self.__instance
except AttributeError:
self.__instance = super(SingletonType, self).__call__(*args, **kwargs)
return self.__instance
class Simpledebugger(object):
__metaclass__ = SingletonType
__start_time = time.time()
def __init__(self, debuglevel=3):
def setDebuglevel(self, new_level):
self.__debuglevel = new_level
def getDebuglevel(self):
return self.__debuglevel
def printdebug(self, level, message):
if self.__debuglevel >= level:
curr_time = time.time() - self.__start_time
caller = inspect.stack()[1][3]
print "[%.02fs][%s] %s" % (curr_time, caller, message)
debuglevel = property(fget=getDebuglevel, fset=setDebuglevel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.