def logEntryExit(getLoggerCallback=logging.getLogger,<EOL>entryExitLogLevel=logging.DEBUG, logArgs=False,<EOL>logTraceback=False):
def entryExitLoggingDecorator(func):<EOL><INDENT>@functools.wraps(func)<EOL>def entryExitLoggingWrap(*args, **kwargs):<EOL><INDENT>if entryExitLogLevel is None:<EOL><INDENT>enabled = False<EOL><DEDENT>else:<EOL><INDENT>logger = getLoggerCallback()<EOL>enabled = logger.isEnabledFor(entryExitLogLevel)<EOL><DEDENT>if not enabled:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>funcName = str(func)<EOL>if logArgs:<EOL><INDENT>argsRepr = '<STR_LIT:U+002CU+0020>'.join(<EOL>[repr(a) for a in args] +<EOL>['<STR_LIT>' % (k,v,) for k,v in kwargs.items()])<EOL><DEDENT>else:<EOL><INDENT>argsRepr = '<STR_LIT>'<EOL><DEDENT>logger.log(<EOL>entryExitLogLevel, "<STR_LIT>", funcName, argsRepr,<EOL>'<STR_LIT>' if not logTraceback else '<STR_LIT>' + repr(traceback.format_stack()))<EOL>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>logger.log(<EOL>entryExitLogLevel, "<STR_LIT>", funcName, argsRepr,<EOL>'<STR_LIT>' if not logTraceback else '<STR_LIT>' + repr(traceback.format_stack()))<EOL><DEDENT><DEDENT>return entryExitLoggingWrap<EOL><DEDENT>return entryExitLoggingDecorator<EOL>
Returns a closure suitable for use as function/method decorator for
    logging entry/exit of function/method.

    getLoggerCallback:    user-supplied callback function that takes no args and
                            returns the logger instance to use for logging.
    entryExitLogLevel:    Log level for logging entry/exit of decorated function;
                            e.g., logging.DEBUG; pass None to disable entry/exit
                            logging.
    logArgs:              If True, also log args
    logTraceback:         If True, also log Traceback information

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

      @logEntryExit()
      def myFunctionBar():
          ...


      @logEntryExit(logTraceback=True)
      @logExceptions()
      def myFunctionGamma():
          ...
          raise RuntimeError("something bad happened")
          ...