RDLogger

Module RDLogger |
[hide private]
[frames] | no frames]

# Source Code for Module RDLogger

     1  # $Id: RDLogger.py 2 2006-05-06 22:54:39Z glandrum $

     2  #

     3  #  Copyright (C) 2005-2006  Greg Landrum and Rational Discovery LLC

     4  #

     5  #   @@ All Rights Reserved  @@

     6  #

     7

     8  from rdBase import EnableLog,DisableLog,AttachFileToLog,LogMessage
     9  import sys,traceback
    10

    11  _levels=['rdApp.debug','rdApp.info','rdApp.warning','rdApp.error']
    12  DEBUG=0
    13  INFO=1
    14  WARNING=2
    15  ERROR=3
    16  CRITICAL=3
    17

    18 -class logger(object):
    19 -  def logIt(self,dest,msg,*args,**kwargs):
    20      if(args):
    21        msg = msg%args
    22      LogMessage(dest,msg+'\n')
    23      if kwargs.get('exc_info',False):
    24        exc_type,exc_val,exc_tb = sys.exc_info()
    25        if exc_type:
    26          LogMessage(dest,'\n')
    27          txt = ''.join(traceback.format_exception(exc_type,exc_val,exc_tb))
    28          LogMessage(dest,txt)
    29 -  def debug(self,msg,*args,**kwargs):
    30      self.logIt('rdApp.debug','DEBUG: '+msg,*args,**kwargs)
    31 -  def error(self,msg,*args,**kwargs):
    32      self.logIt('rdApp.error','ERROR: '+msg,*args,**kwargs)
    33 -  def info(self,msg,*args,**kwargs):
    34      self.logIt('rdApp.info','INFO: '+msg,*args,**kwargs)
    35 -  def warning(self,msg,*args,**kwargs):
    36      self.logIt('rdApp.warning','WARNING: '+msg,*args,**kwargs)
    37 -  def critical(self,msg,*args,**kwargs):
    38      self.logIt('rdApp.error','CRITICAL: '+msg,*args,**kwargs)
    39

    40 -  def setLevel(self,val):
    41      global _levels
    42      for i in range(val,len(_levels)):
    43        EnableLog(_levels[i])
    44      for i in range(0,val):
    45        DisableLog(_levels[i])
    46