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

Source Code for Module RDLogger

 1  # $Id: RDLogger.py 1528 2010-09-26 17:04:37Z glandrum $ 
 2  # 
 3  #  Copyright (C) 2005-2006  Greg Landrum and Rational Discovery LLC 
 4  # 
 5  #   @@ All Rights Reserved @@ 
 6  #  This file is part of the RDKit. 
 7  #  The contents are covered by the terms of the BSD license 
 8  #  which is included in the file license.txt, found at the root 
 9  #  of the RDKit source tree. 
10  # 
11   
12  from rdkit.rdBase import EnableLog,DisableLog,AttachFileToLog,LogMessage 
13  import sys,traceback 
14   
15  _levels=['rdApp.debug','rdApp.info','rdApp.warning','rdApp.error'] 
16  DEBUG=0 
17  INFO=1 
18  WARNING=2 
19  ERROR=3 
20  CRITICAL=3 
21   
22 -class logger(object):
23 - def logIt(self,dest,msg,*args,**kwargs):
24 if(args): 25 msg = msg%args 26 LogMessage(dest,msg+'\n') 27 if kwargs.get('exc_info',False): 28 exc_type,exc_val,exc_tb = sys.exc_info() 29 if exc_type: 30 LogMessage(dest,'\n') 31 txt = ''.join(traceback.format_exception(exc_type,exc_val,exc_tb)) 32 LogMessage(dest,txt)
33 - def debug(self,msg,*args,**kwargs):
34 self.logIt('rdApp.debug','DEBUG: '+msg,*args,**kwargs)
35 - def error(self,msg,*args,**kwargs):
36 self.logIt('rdApp.error','ERROR: '+msg,*args,**kwargs)
37 - def info(self,msg,*args,**kwargs):
38 self.logIt('rdApp.info','INFO: '+msg,*args,**kwargs)
39 - def warning(self,msg,*args,**kwargs):
40 self.logIt('rdApp.warning','WARNING: '+msg,*args,**kwargs)
41 - def critical(self,msg,*args,**kwargs):
42 self.logIt('rdApp.error','CRITICAL: '+msg,*args,**kwargs)
43
44 - def setLevel(self,val):
45 global _levels 46 for i in range(val,len(_levels)): 47 EnableLog(_levels[i]) 48 for i in range(0,val): 49 DisableLog(_levels[i])
50