Created
February 7, 2013 10:22
-
-
Save c7h/4730089 to your computer and use it in GitHub Desktop.
primitive debugging class as Singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on Feb 6, 2013 | |
@author: Christoph Gerneth | |
''' | |
import time | |
import inspect | |
class SingletonType(type): | |
def __call__(self, *args, **kwargs): | |
try: | |
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): | |
self.setDebuglevel(debuglevel) | |
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