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


Python logger.configure方法代码示例

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


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

示例1: test_handlers

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_handlers(capsys, tmpdir):
    file = tmpdir.join("test.log")

    handlers = [
        {"sink": str(file), "format": "FileSink: {message}"},
        {"sink": sys.stdout, "format": "StdoutSink: {message}"},
    ]

    logger.configure(handlers=handlers)
    logger.debug("test")

    out, err = capsys.readouterr()

    assert file.read() == "FileSink: test\n"
    assert out == "StdoutSink: test\n"
    assert err == "" 
开发者ID:Delgan,项目名称:loguru,代码行数:18,代码来源:test_configure.py

示例2: configure_logging

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def configure_logging(level=logging.INFO, enable_loguru=True):
    faulthandler.enable()
    # https://stackoverflow.com/questions/45522159/dont-log-certificate-did-not-match-expected-hostname-error-messages
    logging.getLogger('urllib3.connection').setLevel(logging.CRITICAL)
    logging.getLogger('readability.readability').setLevel(logging.WARNING)
    if enable_loguru:
        loguru_patch()
        logging.basicConfig(
            handlers=[InterceptHandler()], level=level,
            format=LOG_FORMAT, datefmt=LOG_DATE_FORMAT)
        loguru_logger.configure(handlers=[LOGURU_HANDLER])
    else:
        logging.basicConfig(
            level=level, format=LOG_FORMAT, datefmt=LOG_DATE_FORMAT) 
开发者ID:anyant,项目名称:rssant,代码行数:16,代码来源:logger.py

示例3: configure_logger

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def configure_logger(verbosity):
    """Configure the scaffoldgraph cli logger to use tqdm handler"""

    config = {'handlers': []}
    logger.enable('scaffoldgraph')

    if verbosity == 0:
        tqdm_handler['sink'].level = logging.CRITICAL
        tqdm_handler['level'] = 'CRITICAL'
    elif verbosity == 1:
        tqdm_handler['sink'].level = logging.ERROR
        tqdm_handler['level'] = 'ERROR'
    elif verbosity == 2:
        tqdm_handler['sink'].level = logging.WARNING
        tqdm_handler['level'] = 'WARNING'
    elif verbosity == 3:
        tqdm_handler['sink'].level = logging.INFO
        tqdm_handler['level'] = 'INFO'
    elif verbosity == 4:
        tqdm_handler['sink'].level = logging.DEBUG
        tqdm_handler['level'] = 'DEBUG'
    else:  # if < 0 or > 4 is supplied set logger to max level (DEBUG)
        tqdm_handler['sink'].level = logging.DEBUG
        tqdm_handler['level'] = 'DEBUG'

    config["handlers"].append(tqdm_handler)
    logger.configure(**config) 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:29,代码来源:run.py

示例4: enable_logger

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def enable_logger(sink=sys.stderr, level="WARNING"):
    """
    Enable the logging of messages.

    Configure the ``logger`` variable imported from ``loguru``.

    Args:
        sink (file): An opened file pointer, or stream handler. Default to standard error.
        level (str): The log level to use. Possible values are TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL.
            Default to WARNING.
    """
    logger.remove()
    logger.configure(handlers=[{"sink": sink, "level": level}])
    logger.enable("aria2p") 
开发者ID:pawamoy,项目名称:aria2p,代码行数:16,代码来源:__init__.py

示例5: test_keep_extra

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_keep_extra(writer):
    logger.configure(extra=dict(test=123))
    logger.add(writer, format="{extra[test]}")
    logger.opt().debug("")
    logger.opt().log(50, "")

    assert writer.read() == "123\n123\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:9,代码来源:test_opt.py

示例6: test_levels

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_levels(writer):
    levels = [{"name": "my_level", "icon": "X", "no": 12}, {"name": "DEBUG", "icon": "!"}]

    logger.add(writer, format="{level.no}|{level.name}|{level.icon}|{message}")
    logger.configure(levels=levels)

    logger.log("my_level", "test")
    logger.debug("no bug")

    assert writer.read() == ("12|my_level|X|test\n" "10|DEBUG|!|no bug\n") 
开发者ID:Delgan,项目名称:loguru,代码行数:12,代码来源:test_configure.py

示例7: test_extra

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_extra(writer):
    extra = {"a": 1, "b": 9}

    logger.add(writer, format="{extra[a]} {extra[b]}")
    logger.configure(extra=extra)

    logger.debug("")

    assert writer.read() == "1 9\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:11,代码来源:test_configure.py

示例8: test_patcher

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_patcher(writer):
    logger.add(writer, format="{extra[a]} {extra[b]}")
    logger.configure(patcher=lambda record: record["extra"].update(a=1, b=2))

    logger.debug("")

    assert writer.read() == "1 2\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:9,代码来源:test_configure.py

示例9: test_dict_unpacking

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_dict_unpacking(writer):
    config = {
        "handlers": [{"sink": writer, "format": "{level.no} - {extra[x]} {extra[z]} - {message}"}],
        "levels": [{"name": "test", "no": 30}],
        "extra": {"x": 1, "y": 2, "z": 3},
    }

    logger.debug("NOPE")

    logger.configure(**config)

    logger.log("test", "Yes!")

    assert writer.read() == "30 - 1 3 - Yes!\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:16,代码来源:test_configure.py

示例10: test_returned_ids

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_returned_ids(capsys):
    ids = logger.configure(
        handlers=[
            {"sink": sys.stdout, "format": "{message}"},
            {"sink": sys.stderr, "format": "{message}"},
        ]
    )

    assert len(ids) == 2

    logger.debug("Test")

    out, err = capsys.readouterr()

    assert out == "Test\n"
    assert err == "Test\n"

    for i in ids:
        logger.remove(i)

    logger.debug("Nope")

    out, err = capsys.readouterr()

    assert out == ""
    assert err == "" 
开发者ID:Delgan,项目名称:loguru,代码行数:28,代码来源:test_configure.py

示例11: test_dont_reset_by_default

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_dont_reset_by_default(writer):
    logger.configure(extra={"a": 1}, patcher=lambda r: r["extra"].update(b=2))
    logger.level("b", no=30)
    logger.add(writer, format="{level} {extra[a]} {extra[b]} {message}")

    logger.configure()

    logger.log("b", "Test")

    assert writer.read() == "b 1 2 Test\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:12,代码来源:test_configure.py

示例12: test_reset_previous_handlers

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

    logger.configure(handlers=[])

    logger.debug("Test")

    assert writer.read() == "" 
开发者ID:Delgan,项目名称:loguru,代码行数:10,代码来源:test_configure.py

示例13: test_reset_previous_extra

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_reset_previous_extra(writer):
    logger.configure(extra={"a": 123})
    logger.add(writer, format="{extra[a]}", catch=False)

    logger.configure(extra={})

    with pytest.raises(KeyError):
        logger.debug("Nope") 
开发者ID:Delgan,项目名称:loguru,代码行数:10,代码来源:test_configure.py

示例14: test_dont_reset_previous_levels

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_dont_reset_previous_levels(writer):
    logger.level("abc", no=30)

    logger.configure(levels=[])

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

    logger.log("abc", "Test")

    assert writer.read() == "abc Test\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:12,代码来源:test_configure.py

示例15: test_configure_handler_using_new_level

# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import configure [as 别名]
def test_configure_handler_using_new_level(writer):
    logger.configure(
        levels=[{"name": "CONF_LVL", "no": 33, "icon": "", "color": ""}],
        handlers=[
            {"sink": writer, "level": "CONF_LVL", "format": "{level.name} {level.no} {message}"}
        ],
    )

    logger.log("CONF_LVL", "Custom")
    assert writer.read() == "CONF_LVL 33 Custom\n" 
开发者ID:Delgan,项目名称:loguru,代码行数:12,代码来源:test_configure.py


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