Back to index

plone3  3.1.7
utils.py
Go to the documentation of this file.
00001 import logging
00002 import sys
00003 import traceback
00004 
00005 logger = logging.getLogger('CMFFormController')
00006 
00007 def log(summary='', text='', log_level=logging.INFO):
00008     logger.log(log_level, '%s \n%s' % (summary, text))
00009 
00010 # Enable scripts to get the string value of an exception
00011 # even if the thrown exception is a string and not a
00012 # subclass of Exception.
00013 def exceptionString():
00014     s = sys.exc_info()[:2]  # don't assign the traceback to s
00015                             # (otherwise will generate a circular reference)
00016     if s[0] == None:
00017         return None
00018     if isinstance(s[0], basestring):
00019         return s[0]
00020     return str(s[1])
00021 
00022 # provide a way of dumping an exception to the log even if we
00023 # catch it and otherwise ignore it
00024 def logException():
00025     """Dump an exception to the log"""
00026     log(summary=str(exceptionString()),
00027         text='\n'.join(traceback.format_exception(*sys.exc_info())),
00028         log_level=logging.WARNING)