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


Python logger.level方法代码示例

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


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

示例1: emit

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

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def setup_logger() -> None:
    """Set up stderr logging format.

    The logging format and colors can be overridden by setting up the
    environment variables such as ``LOGURU_FORMAT``.
    See `Loguru documentation`_ for details.

    .. _Loguru documentation: https://loguru.readthedocs.io/en/stable/api/logger.html#env
    """
    logger.remove()  # Remove the default setting

    # Set up the preferred logging colors and format unless overridden by its environment variable
    logger.level("INFO", color=environ.get("LOGURU_INFO_COLOR") or "<white>")
    logger.level("DEBUG", color=environ.get("LOGURU_DEBUG_COLOR") or "<d><white>")
    log_format = environ.get("LOGURU_FORMAT") or (
        # "<green>{time:YYYY-MM-DD HH:mm:ss}</green> "
        "<b><level>{level: <8}</level></b> "
        "| <level>{message}</level>"
    )
    logger.add(sys.stderr, format=log_format)

    # By default all the logging messages are disabled
    logger.enable("charger") 
开发者ID:ding-lab,项目名称:CharGer,代码行数:25,代码来源:console.py

示例3: test_add_existing_level

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_add_existing_level(writer):
    logger.level("INFO", color="<red>")
    fmt = "{level.icon} + <level>{level.name}</level> + {level.no} = {message}"
    logger.add(writer, format=fmt, colorize=True)

    logger.info("a")
    logger.log("INFO", "b")
    logger.log(10, "c")
    logger.log(20, "d")

    assert writer.read() == parse(
        "ℹ️ + <red>INFO</red> + 20 = a\n"
        "ℹ️ + <red>INFO</red> + 20 = b\n"
        "  + Level 10\x1b[0m + 10 = c\n"
        "  + Level 20\x1b[0m + 20 = d\n"
    ) 
开发者ID:Delgan,项目名称:loguru,代码行数:18,代码来源:test_levels.py

示例4: test_edit_level

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_edit_level(writer):
    logger.level("info", no=11, color="<bold>", icon="[?]")
    fmt = "<level>->{level.no}, {level.name}, {level.icon}, {message}<-</level>"
    logger.add(writer, format=fmt, colorize=True)

    logger.log("info", "a")

    logger.level("info", icon="[!]")
    logger.log("info", "b")

    logger.level("info", color="<red>")
    logger.log("info", "c")

    assert writer.read() == parse(
        "<bold>->11, info, [?], a<-</bold>\n"
        "<bold>->11, info, [!], b<-</bold>\n"
        "<red>->11, info, [!], c<-</red>\n"
    ) 
开发者ID:Delgan,项目名称:loguru,代码行数:20,代码来源:test_levels.py

示例5: emit

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

示例6: test_formatting

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_formatting(writer, make_logging_logger):
    fmt = "{name} - {file.name} - {function} - {level.name} - {level.no} - {line} - {module} - {message}"
    expected = "tests.test_interception - test_interception.py - test_formatting - DEBUG - 10 - 31 - test_interception - This is the message\n"

    logging_logger = make_logging_logger("tests", InterceptHandler())

    logger.add(writer, format=fmt)

    logging_logger.debug("This is the %s", "message")

    result = writer.read()
    assert result == expected 
开发者ID:Delgan,项目名称:loguru,代码行数:14,代码来源:test_interception.py

示例7: test_level_is_no

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_level_is_no(writer, make_logging_logger):
    logging_logger = make_logging_logger("tests", InterceptHandler())
    logger.add(writer, format="<lvl>{level.no} - {level.name} - {message}</lvl>", colorize=True)

    logging_logger.log(12, "Hop")

    result = writer.read()
    assert result == "12 - Level 12 - Hop\x1b[0m\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:10,代码来源:test_interception.py

示例8: test_level_does_not_exist

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_level_does_not_exist(writer, make_logging_logger):
    logging.addLevelName(152, "FANCY_LEVEL")
    logging_logger = make_logging_logger("tests", InterceptHandler())
    logger.add(writer, format="<lvl>{level.no} - {level.name} - {message}</lvl>", colorize=True)

    logging_logger.log(152, "Nop")

    result = writer.read()
    assert result == "152 - Level 152 - Nop\x1b[0m\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:11,代码来源:test_interception.py

示例9: test_level_exist_builtin

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_level_exist_builtin(writer, make_logging_logger):
    logging_logger = make_logging_logger("tests", InterceptHandler())
    logger.add(writer, format="<lvl>{level.no} - {level.name} - {message}</lvl>", colorize=True)

    logging_logger.error("Error...")

    result = writer.read()
    assert result == "\x1b[31m\x1b[1m40 - ERROR - Error...\x1b[0m\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:10,代码来源:test_interception.py

示例10: test_filter_dict_with_custom_level

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_filter_dict_with_custom_level(writer):
    logger.level("MY_LEVEL", 6, color="", icon="")
    logger.add(writer, level=0, filter={"tests": "MY_LEVEL"}, format="{message}")
    logger.log(3, "No")
    logger.log(9, "Yes")
    assert writer.read() == "Yes\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:8,代码来源:test_add_option_filter.py

示例11: test_record

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

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

示例13: test_exception_log_funcion

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

    try:
        1 / 0
    except:
        logger.opt(exception=True).log(50, "Error")

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

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

示例14: test_lazy

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_lazy(writer):
    counter = 0

    def laziness():
        nonlocal counter
        counter += 1
        return counter

    logger.add(writer, level=10, format="{level.no} => {message}")

    logger.opt(lazy=True).log(10, "1: {lazy}", lazy=laziness)
    logger.opt(lazy=True).log(5, "2: {0}", laziness)

    logger.remove()

    logger.opt(lazy=True).log(20, "3: {}", laziness)

    a = logger.add(writer, level=15, format="{level.no} => {message}")
    b = logger.add(writer, level=20, format="{level.no} => {message}")

    logger.log(17, "4: {}", counter)
    logger.opt(lazy=True).log(14, "5: {lazy}", lazy=lambda: counter)

    logger.remove(a)

    logger.opt(lazy=True).log(16, "6: {0}", lambda: counter)

    logger.opt(lazy=True).info("7: {}", laziness)
    logger.debug("7: {}", counter)

    assert writer.read() == "10 => 1: 1\n17 => 4: 1\n20 => 7: 2\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:33,代码来源:test_opt.py

示例15: test_colors_with_level

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import level [as 别名]
def test_colors_with_level(writer, colorize):
    logger.add(writer, format="{message}", colorize=colorize)
    logger.level("DEBUG", color="<green>")
    logger.opt(colors=True).debug("a <level>level</level> b")
    assert writer.read() == parse("a <green>level</green> b\n", strip=not colorize) 
开发者ID:Delgan,项目名称:loguru,代码行数:7,代码来源:test_opt.py


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