Created
October 18, 2012 15:09
-
-
Save sandromello/3912444 to your computer and use it in GitHub Desktop.
Debugger
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
import logging | |
LOGGING_LEVELS = {'critical': logging.CRITICAL, | |
'error': logging.ERROR, | |
'warning': logging.WARNING, | |
'info': logging.INFO, | |
'debug': logging.DEBUG} | |
class Debug(object): | |
def __init__(self, caller, debugfile='pleskydebug.log', type='default', debug='False'): | |
self.debugfile = debugfile | |
self.type = type | |
self._debug = debug | |
try: self.caller = caller.__class__.__name__ | |
except: self.caller = 'Unknown' | |
@property | |
def debug(self): | |
return self._debug | |
@debug.setter | |
def debug(self, debug): | |
self._debug = debug | |
def logger(self, msg, level='info'): | |
if self.debug: | |
logging.basicConfig(level=LOGGING_LEVELS.get(level), filename=self.debugfile, | |
format='%(asctime)s %(levelname)s: %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S') | |
if self.type == 'packet' or self.type == 'all': | |
logging.info('[%s] - %s'% (self.caller, msg)) | |
elif self.type == 'default' or self.type == 'all': | |
logging.info('[%s] - %s'% (self.caller, msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment