當前位置: 首頁>>代碼示例>>Python>>正文


Python logging.currentframe方法代碼示例

本文整理匯總了Python中logging.currentframe方法的典型用法代碼示例。如果您正苦於以下問題:Python logging.currentframe方法的具體用法?Python logging.currentframe怎麽用?Python logging.currentframe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在logging的用法示例。


在下文中一共展示了logging.currentframe方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: emit

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def emit(self, record: logging.LogRecord) -> None:  # pragma: no cover
        # Get corresponding Loguru level if it exists
        try:
            level = logger.level(record.levelname).name
        except ValueError:
            level = str(record.levelno)

        # Find caller from where originated the logged message
        frame, depth = logging.currentframe(), 2
        while frame.f_code.co_filename == logging.__file__:  # noqa: WPS609
            frame = cast(FrameType, frame.f_back)
            depth += 1

        logger.opt(depth=depth, exception=record.exc_info).log(
            level, record.getMessage(),
        ) 
開發者ID:nsidnev,項目名稱:fastapi-realworld-example-app,代碼行數:18,代碼來源:logging.py

示例2: findCaller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def findCaller(self, stack_info=False):
        f = logging.currentframe()
        f = f.f_back
        rv = "(unknown file)", 0, "(unknown function)", None
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename in _ignore_srcfiles:
                f = f.f_back
                continue
            sinfo = None
            if stack_info:
                sio = io.StringIO()
                sio.write('Stack (most recent call last):\n')
                traceback.print_stack(f, file=sio)
                sinfo = sio.getvalue()
                if sinfo[-1] == '\n':
                    sinfo = sinfo[:-1]
                sio.close()
            rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
            break
        return rv 
開發者ID:Kaggle,項目名稱:docker-python,代碼行數:24,代碼來源:log.py

示例3: find_log_caller_module

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def find_log_caller_module(record: logging.LogRecord) -> Optional[str]:
    '''Find the module name corresponding to where this record was logged.

    Sadly `record.module` is just the innermost component of the full
    module name, so we have to go reconstruct this ourselves.
    '''
    # Repeat a search similar to that in logging.Logger.findCaller.
    # The logging call should still be on the stack somewhere; search until
    # we find something in the same source file, and that should give the
    # right module name.
    f = logging.currentframe()
    while True:
        if f.f_code.co_filename == record.pathname:
            return f.f_globals.get('__name__')
        if f.f_back is None:
            return None
        f = f.f_back 
開發者ID:zulip,項目名稱:zulip,代碼行數:19,代碼來源:logging_util.py

示例4: find_caller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def find_caller(stack_info=None):
    """
    Find the stack frame of the caller so that we can note the source file name, line number and
    function name.

    Note: This is based on logging/__init__.py:findCaller and modified so it takes into account
    this file - https://hg.python.org/cpython/file/2.7/Lib/logging/__init__.py#l1233
    """
    rv = '(unknown file)', 0, '(unknown function)'

    try:
        f = logging.currentframe().f_back
        while hasattr(f, 'f_code'):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename in (_srcfile, logging._srcfile):  # This line is modified.
                f = f.f_back
                continue
            rv = (filename, f.f_lineno, co.co_name)
            break
    except Exception:
        pass

    return rv 
開發者ID:StackStorm,項目名稱:st2,代碼行數:26,代碼來源:log.py

示例5: setup_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def setup_logging(streams=(sys.stderr,)):
  """Configures Python logging the way the TensorBoard team likes it.

  This should be called exactly once at the beginning of main().

  Args:
    streams: An iterable of open files. Logs are written to each.

  :type streams: tuple[file]
  """
  # NOTE: Adding a level parameter to this method would be a bad idea
  #       because Python and ABSL disagree on the level numbers.
  locale.setlocale(locale.LC_ALL, '')
  tf.logging.set_verbosity(tf.logging.WARN)
  # TODO(jart): Make the default TensorFlow logger behavior great again.
  logging.currentframe = _hack_the_main_frame
  handlers = [LogHandler(s) for s in streams]
  formatter = LogFormatter()
  for handler in handlers:
    handler.setFormatter(formatter)
  tensorflow_logger = logging.getLogger('tensorflow')
  tensorflow_logger.handlers = handlers
  werkzeug_logger = logging.getLogger('werkzeug')
  werkzeug_logger.setLevel(logging.WARNING)
  werkzeug_logger.handlers = handlers 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:27,代碼來源:util.py

示例6: find_caller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def find_caller(levels_to_go_up=0):
    """
    Find the stack frame of the caller so that we can note the source
    file name, line number and function name.

    Based on findCaller() from logging module
    but allows to go higher back on stack

    :param levels_to_go_up: 0 - info about 'calling location' of caller of findCaller(); 1 - 'calling -1 location'
    :return:
    """
    f = logging.currentframe()
    # On some versions of IronPython, currentframe() returns None if
    # IronPython isn't run with -X:Frames.
    rv = "(unknown file)", 0, "(unknown function)", None
    while hasattr(f, "f_code"):
        co = f.f_code
        filename = os.path.normcase(co.co_filename)
        if filename == _srcfile:
            f = f.f_back
            continue
        for lv in range(levels_to_go_up):
            f = f.f_back
            if hasattr(f, "f_code"):
                co = f.f_code
            else:
                break

        rv = (co.co_filename, f.f_lineno, co.co_name)
        break
    return rv 
開發者ID:nokia,項目名稱:moler,代碼行數:33,代碼來源:loghelper.py

示例7: findCaller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def findCaller(self):
        f = logging.currentframe().f_back.f_back
        rv = "(unknown file)", 0, "(unknown function)"
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if "logger" in filename:  # This line is modified.
                f = f.f_back
                continue
            filename = filename + " " + co.co_name
            rv = (filename, f.f_lineno, co.co_name)
            break
        return rv 
開發者ID:alfa-addon,項目名稱:addon,代碼行數:15,代碼來源:logger.py

示例8: findCaller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def findCaller(self, stack_info=False):
        """
        Overload built-in findCaller method
        to omit not only logging/__init__.py but also the current file
        """
        f = logging.currentframe()
        # On some versions of IronPython, currentframe() returns None if
        # IronPython isn't run with -X:Frames.
        if f is not None:
            f = f.f_back
        rv = "(unknown file)", 0, "(unknown function)", None
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename in (logging._srcfile, _srcfile):
                f = f.f_back
                continue
            sinfo = None
            if stack_info:
                sio = io.StringIO()
                sio.write('Stack (most recent call last):\n')
                traceback.print_stack(f, file=sio)
                sinfo = sio.getvalue()
                if sinfo[-1] == '\n':
                    sinfo = sinfo[:-1]
                sio.close()
            rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
            break
        return rv 
開發者ID:freenas,項目名稱:py-SMART,代碼行數:31,代碼來源:utils.py

示例9: emit

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def emit(self, record):
        # Get corresponding Loguru level if it exists
        try:
            level = logger.level(record.levelname).name
        except ValueError:
            level = record.levelno

        # Find caller from where originated the logged message
        frame, depth = logging.currentframe(), 2
        while frame.f_code.co_filename == logging.__file__:
            frame = frame.f_back
            depth += 1

        logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage()) 
開發者ID:Delgan,項目名稱:loguru,代碼行數:16,代碼來源:test_interception.py

示例10: findCaller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def findCaller(self):
        f = logging.currentframe().f_back.f_back
        rv = "(unknown file)", 0, "(unknown function)"
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if "logger" in filename: # This line is modified.
                f = f.f_back
                continue
            filename =filename + " " + co.co_name
            rv = (filename , f.f_lineno, co.co_name)
            break
        return rv 
開發者ID:pelisalacarta-ce,項目名稱:pelisalacarta-ce,代碼行數:15,代碼來源:logger.py

示例11: findCaller

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import currentframe [as 別名]
def findCaller(self, stack_info=False, stacklevel=1):
    """Finds the frame of the calling method on the stack.

    This method skips any frames registered with the
    ABSLLogger and any methods from this file, and whatever
    method is currently being used to generate the prefix for the log
    line.  Then it returns the file name, line number, and method name
    of the calling method.  An optional fourth item may be returned,
    callers who only need things from the first three are advised to
    always slice or index the result rather than using direct unpacking
    assignment.

    Args:
      stack_info: bool, when True, include the stack trace as a fourth item
          returned.  On Python 3 there are always four items returned - the
          fourth will be None when this is False.  On Python 2 the stdlib
          base class API only returns three items.  We do the same when this
          new parameter is unspecified or False for compatibility.

    Returns:
      (filename, lineno, methodname[, sinfo]) of the calling method.
    """
    f_to_skip = ABSLLogger._frames_to_skip
    # Use sys._getframe(2) instead of logging.currentframe(), it's slightly
    # faster because there is one less frame to traverse.
    frame = sys._getframe(2)  # pylint: disable=protected-access

    while frame:
      code = frame.f_code
      if (_LOGGING_FILE_PREFIX not in code.co_filename and
          (code.co_filename, code.co_name,
           code.co_firstlineno) not in f_to_skip and
          (code.co_filename, code.co_name) not in f_to_skip):
        if six.PY2 and not stack_info:
          return (code.co_filename, frame.f_lineno, code.co_name)
        else:
          sinfo = None
          if stack_info:
            out = io.StringIO()
            out.write(u'Stack (most recent call last):\n')
            traceback.print_stack(frame, file=out)
            sinfo = out.getvalue().rstrip(u'\n')
          return (code.co_filename, frame.f_lineno, code.co_name, sinfo)
      frame = frame.f_back 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:46,代碼來源:__init__.py


注:本文中的logging.currentframe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。