Skip to content

Instantly share code, notes, and snippets.

@sandromello
Created October 18, 2012 15:09
Show Gist options
  • Save sandromello/3912444 to your computer and use it in GitHub Desktop.
Save sandromello/3912444 to your computer and use it in GitHub Desktop.
Debugger
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