def logExceptions(logger=None):
logger = (logger if logger is not None else logging.getLogger(__name__))<EOL>def exceptionLoggingDecorator(func):<EOL><INDENT>@functools.wraps(func)<EOL>def exceptionLoggingWrap(*args, **kwargs):<EOL><INDENT>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>except:<EOL><INDENT>logger.exception(<EOL>"<STR_LIT>",<EOL>sys.exc_info()[<NUM_LIT:1>], func, '<STR_LIT>'.join(traceback.format_stack()), )<EOL>raise<EOL><DEDENT><DEDENT>return exceptionLoggingWrap<EOL><DEDENT>return exceptionLoggingDecorator<EOL>
Returns a closure suitable for use as function/method decorator for
    logging exceptions that leave the scope of the decorated function. Exceptions
    are logged at ERROR level.

    logger:    user-supplied logger instance. Defaults to logging.getLogger.

    Usage Example:
      NOTE: logging must be initialized *before* any loggers are created, else
        there will be no output; see nupic.support.initLogging()

      @logExceptions()
      def myFunctionFoo():
          ...
          raise RuntimeError("something bad happened")
          ...