当前位置: 首页>>代码示例>>Python>>正文


Python logger.opt方法代码示例

本文整理汇总了Python中loguru.logger.opt方法的典型用法代码示例。如果您正苦于以下问题:Python logger.opt方法的具体用法?Python logger.opt怎么用?Python logger.opt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在loguru.logger的用法示例。


在下文中一共展示了logger.opt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: emit

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [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: resume

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def resume(self, downloads: List[Download]) -> List[bool]:
        """
        Resume (unpause) the given downloads.

        Parameters:
            downloads: the list of downloads to resume.

        Returns:
            Success or failure of the operation for each given download.
        """
        # TODO: batch/multicall candidate
        result = []

        for download in downloads:
            try:
                self.client.unpause(download.gid)
            except ClientException as error:
                logger.debug(f"Failed to resume download {download.gid}")
                logger.opt(exception=True).trace(error)
                result.append(error)
            else:
                result.append(True)

        return result 
开发者ID:pawamoy,项目名称:aria2p,代码行数:26,代码来源:api.py

示例3: followed_by

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def followed_by(self):
        """
        List of downloads generated as the result of this download.

        Returns a list of instances of [`Download`][aria2p.downloads.Download].
        """
        if self._followed_by is None:
            result = []
            for gid in self.followed_by_ids:
                try:
                    result.append(self.api.get_download(gid))
                except ClientException as error:
                    logger.warning(f"Can't find download with GID {gid}, try to update download {self.gid} ({id(self)}")
                    logger.opt(exception=True).trace(error)
            self._followed_by = result
        return self._followed_by 
开发者ID:pawamoy,项目名称:aria2p,代码行数:18,代码来源:downloads.py

示例4: following

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def following(self):
        """
        The download this download is following.

        Returns an instance of [`Download`][aria2p.downloads.Download].
        """
        if not self._following:
            following_id = self.following_id
            if following_id:
                try:
                    self._following = self.api.get_download(following_id)
                except ClientException as error:
                    logger.warning(
                        f"Can't find download with GID {following_id}, try to update download {self.gid} ({id(self)}"
                    )
                    logger.opt(exception=True).trace(error)
                    self._following = None
        return self._following 
开发者ID:pawamoy,项目名称:aria2p,代码行数:20,代码来源:downloads.py

示例5: test_exception

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_exception(make_logging_logger, capsys, use_opt):
    make_logging_logger("tests", StreamHandler(sys.stderr))
    logger.add(PropagateHandler(), format="{message}")

    try:
        1 / 0
    except:
        if use_opt:
            logger.opt(exception=True).error("Oops...")
        else:
            logger.exception("Oops...")

    out, err = capsys.readouterr()
    lines = err.strip().splitlines()

    error = "ZeroDivisionError: division by zero"

    assert out == ""
    assert lines[0] == "Oops..."
    assert lines[-1] == error
    assert err.count(error) == 1 
开发者ID:Delgan,项目名称:loguru,代码行数:23,代码来源:test_propagation.py

示例6: emit

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def emit(self, record):
        logger_opt = logger.opt(depth=6, exception=record.exc_info)
        logger_opt.log(record.levelname, record.getMessage()) 
开发者ID:anyant,项目名称:rssant,代码行数:5,代码来源:loguru_patch.py

示例7: emit

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def emit(self, record):
        logger_opt = logger.opt(depth=6, exception=record.exc_info)
        logger_opt.log(self._get_level(record), record.getMessage()) 
开发者ID:aiogram,项目名称:bot,代码行数:5,代码来源:logging.py

示例8: pause

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def pause(self, downloads: List[Download], force: bool = False) -> List[bool]:
        """
        Remove the given downloads from the list.

        Parameters:
            downloads: the list of downloads to remove.
            force: whether to pause immediately without contacting servers or not.

        Returns:
            Success or failure of the operation for each given download.
        """
        # TODO: batch/multicall candidate
        if force:
            pause_func = self.client.force_pause
        else:
            pause_func = self.client.pause

        result = []

        for download in downloads:
            try:
                pause_func(download.gid)
            except ClientException as error:
                logger.debug(f"Failed to pause download {download.gid}")
                logger.opt(exception=True).trace(error)
                result.append(error)
            else:
                result.append(True)

        return result 
开发者ID:pawamoy,项目名称:aria2p,代码行数:32,代码来源:api.py

示例9: root_files_paths

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def root_files_paths(self):
        """
        Return the unique set of directories/files for this download.

        Instead of returning all the leaves like self.files,
        return the relative root directories if any, and relative root files.

        This property is useful when we need to list the directories and files
        in order to move or copy them. We don't want to copy files one by one,
        but rather entire directories at once when possible.

        Examples:

            # download dir is /a/b.
            >>> self.files
            ["/a/b/c/1.txt", "/a/b/c/2.txt", "/a/b/3.txt"]
            >>> self.root_files_paths
            ["/a/b/c", "/a/b/3.txt"]
        """
        if not self._root_files_paths:
            paths = []
            for file in self.files:
                if file.is_metadata:
                    continue
                try:
                    relative_path = file.path.relative_to(self.dir)
                except ValueError as error:
                    logger.warning(f"Can't determine file path '{file.path}' relative to '{self.dir}'")
                    logger.opt(exception=True).trace(error)
                else:
                    path = self.dir / relative_path.parts[0]
                    if path not in paths:
                        paths.append(path)
            self._root_files_paths = paths
        return self._root_files_paths 
开发者ID:pawamoy,项目名称:aria2p,代码行数:37,代码来源:downloads.py

示例10: emit

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [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

示例11: test_record

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_record(writer):
    logger.add(writer, format="{message}")

    logger.opt(record=True).debug("1")
    logger.opt(record=True).debug("2 {record[level]}")
    logger.opt(record=True).log(11, "3 {0} {a} {record[level].no}", 4, a=5)

    assert writer.read() == "1\n2 DEBUG\n3 4 5 11\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:10,代码来源:test_opt.py

示例12: test_record_in_kwargs_too

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_record_in_kwargs_too(writer):
    logger.add(writer, catch=False)

    with pytest.raises(TypeError, match=r"The message can't be formatted"):
        logger.opt(record=True).info("Foo {record}", record=123) 
开发者ID:Delgan,项目名称:loguru,代码行数:7,代码来源:test_opt.py

示例13: test_record_not_in_extra

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_record_not_in_extra():
    extra = None

    def sink(message):
        nonlocal extra
        extra = message.record["extra"]

    logger.add(sink, catch=False)

    logger.opt(record=True).info("Test")

    assert extra == {} 
开发者ID:Delgan,项目名称:loguru,代码行数:14,代码来源:test_opt.py

示例14: test_exception_boolean

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_exception_boolean(writer):
    logger.add(writer, format="{level.name}: {message}")

    try:
        1 / 0
    except:
        logger.opt(exception=True).debug("Error {0} {record}", 1, record="test")

    lines = writer.read().strip().splitlines()

    assert lines[0] == "DEBUG: Error 1 test"
    assert lines[-1] == "ZeroDivisionError: division by zero" 
开发者ID:Delgan,项目名称:loguru,代码行数:14,代码来源:test_opt.py

示例15: test_exception_exc_info

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import opt [as 别名]
def test_exception_exc_info(writer):
    logger.add(writer, format="{message}")

    try:
        1 / 0
    except:
        exc_info = sys.exc_info()

    logger.opt(exception=exc_info).debug("test")

    lines = writer.read().strip().splitlines()

    assert lines[0] == "test"
    assert lines[-1] == "ZeroDivisionError: division by zero" 
开发者ID:Delgan,项目名称:loguru,代码行数:16,代码来源:test_opt.py


注:本文中的loguru.logger.opt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。