-#SFA access log initialization
-TMPDIR = os.getenv("TMPDIR", "/tmp")
-SFA_HTTPD_ACCESS_LOGFILE = TMPDIR + "/" + 'sfa_httpd_access.log'
-SFA_ACCESS_LOGFILE='/var/log/sfa_access.log'
-logger=logging.getLogger()
-#logger.setLevel(logging.INFO)
-logger.setLevel(logging.DEBUG)
-
-try:
- logfile=logging.FileHandler(SFA_ACCESS_LOGFILE)
-except IOError:
- # This is usually a permissions error becaue the file is
- # owned by root, but httpd is trying to access it.
- logfile=logging.FileHandler(SFA_HTTPD_ACCESS_LOGFILE)
+ # shorthand to avoid having to import logging all over the place
+ def setLevelDebug(self):
+ self.logger.setLevel(logging.DEBUG)
+
+ # define a verbose option with s/t like
+ # parser.add_option("-v", "--verbose", action="count", dest="verbose", default=0)
+ # and pass the coresponding options.verbose to this method to adjust level
+ def setLevelFromOptVerbose(self,verbose):
+ if verbose==0:
+ self.logger.setLevel(logging.WARNING)
+ elif verbose==1:
+ self.logger.setLevel(logging.INFO)
+ elif verbose==2:
+ self.logger.setLevel(logging.DEBUG)
+
+ ####################
+ def wrap(fun):
+ def wrapped(self,msg,*args,**kwds):
+ native=getattr(self.logger,fun.__name__)
+ return native(msg,*args,**kwds)
+ #wrapped.__doc__=native.__doc__
+ return wrapped
+
+ @wrap
+ def critical(): pass
+ @wrap
+ def error(): pass
+ @wrap
+ def warning(): pass
+ @wrap
+ def info(): pass
+ @wrap
+ def debug(): pass
+
+ # logs an exception - use in an except statement
+ def log_exc(self,message):
+ self.error("%s BEG TRACEBACK"%message+"\n"+traceback.format_exc().strip("\n"))
+ self.error("%s END TRACEBACK"%message)
+
+ def log_exc_critical(self,message):
+ self.critical("%s BEG TRACEBACK"%message+"\n"+traceback.format_exc().strip("\n"))
+ self.critical("%s END TRACEBACK"%message)