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


Python logger.enable方法代碼示例

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


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

示例1: initialize_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def initialize_logger(name: str, log_level: str) -> None:
    logger.remove()

    if log_level == QUIET_LOG_LEVEL:
        logger.disable(name)
        return

    if log_level == "DEBUG":
        log_format = (
            "<level>{level: <8}</level> | "
            "<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
        )
    else:
        log_format = "<level>[{level}]</level> {message}"

    logger.add(sys.stdout, colorize=True, format=log_format, level=log_level)
    logger.enable(name)
    ptr.set_logger(True)
    sqlite.set_logger(True)
    appconfigpy.set_logger(True) 
開發者ID:thombashi,項目名稱:sqlitebiter,代碼行數:22,代碼來源:__main__.py

示例2: set_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def set_logger(is_enable: bool, propagation_depth: int = 2) -> None:
    if is_enable:
        logger.enable(MODULE_NAME)
    else:
        logger.disable(MODULE_NAME)

    if propagation_depth <= 0:
        return

    tabledata.set_logger(is_enable, propagation_depth - 1)
    sqliteschema.set_logger(is_enable, propagation_depth - 1)

    try:
        import pytablereader

        pytablereader.set_logger(is_enable, propagation_depth - 1)
    except (ImportError, TypeError):
        pass 
開發者ID:thombashi,項目名稱:SimpleSQLite,代碼行數:20,代碼來源:_logger.py

示例3: set_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def set_logger(is_enable, propagation_depth=2):
    if is_enable:
        logger.enable(MODULE_NAME)
    else:
        logger.disable(MODULE_NAME)

    if propagation_depth <= 0:
        return

    dataproperty.set_logger(is_enable, propagation_depth - 1)

    try:
        import simplesqlite

        simplesqlite.set_logger(is_enable, propagation_depth - 1)
    except (ImportError, TypeError):
        pass 
開發者ID:thombashi,項目名稱:pytablereader,代碼行數:19,代碼來源:_logger.py

示例4: setup_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [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

示例5: set_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def set_logger(is_enable: bool, propagation_depth: int = 1) -> None:
    if is_enable:
        logger.enable(MODULE_NAME)
    else:
        logger.disable(MODULE_NAME)

    if propagation_depth <= 0:
        return

    dataproperty.set_logger(is_enable, propagation_depth - 1)

    try:
        import simplesqlite

        simplesqlite.set_logger(is_enable, propagation_depth - 1)
    except ImportError:
        pass

    try:
        import pytablereader

        pytablereader.set_logger(is_enable, propagation_depth - 1)
    except ImportError:
        pass 
開發者ID:thombashi,項目名稱:pytablewriter,代碼行數:26,代碼來源:_logger.py

示例6: caplog

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def caplog(_caplog):  # noqa: F811
    """A fixture to capture loguru logging messages.

    Copied from https://loguru.readthedocs.io/en/stable/resources/migration.html
    """

    class PropagateHandler(logging.Handler):
        def emit(self, record):
            logging.getLogger(record.name).handle(record)

    logger.enable("charger")
    handler_id = logger.add(PropagateHandler(), format="{message}")
    yield _caplog
    logger.remove(handler_id)
    logger.disable("charger") 
開發者ID:ding-lab,項目名稱:CharGer,代碼行數:17,代碼來源:conftest.py

示例7: set_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def set_logger(is_enable):
    if is_enable:
        logger.enable(MODULE_NAME)
    else:
        logger.disable(MODULE_NAME)

    simplesqlite.set_logger(is_enable)
    subprocrunner.set_logger(is_enable) 
開發者ID:thombashi,項目名稱:tcconfig,代碼行數:10,代碼來源:_logger.py

示例8: configure_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [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

示例9: enable_logger

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [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

示例10: test_enable

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_enable(writer, name, should_log):
    logger.add(writer, format="{message}")
    logger.disable("")
    logger.enable(name)
    logger.debug("message")
    result = writer.read()

    if should_log:
        assert result == "message\n"
    else:
        assert result == "" 
開發者ID:Delgan,項目名稱:loguru,代碼行數:13,代碼來源:test_activation.py

示例11: test_log_before_enable

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_log_before_enable(writer):
    logger.add(writer, format="{message}")
    logger.disable("")
    logger.debug("nope")
    logger.enable("tests")
    logger.debug("yes")
    result = writer.read()
    assert result == "yes\n" 
開發者ID:Delgan,項目名稱:loguru,代碼行數:10,代碼來源:test_activation.py

示例12: test_log_before_disable

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_log_before_disable(writer):
    logger.add(writer, format="{message}")
    logger.enable("")
    logger.debug("yes")
    logger.disable("tests")
    logger.debug("nope")
    result = writer.read()
    assert result == "yes\n" 
開發者ID:Delgan,項目名稱:loguru,代碼行數:10,代碼來源:test_activation.py

示例13: test_multiple_activations

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_multiple_activations():
    n = lambda: len(logger._core.activation_list)

    assert n() == 0
    logger.enable("")
    assert n() == 0
    logger.disable("")
    assert n() == 1
    logger.enable("foo")
    assert n() == 2
    logger.enable("foo.bar")
    assert n() == 2
    logger.disable("foo")
    assert n() == 1
    logger.disable("foo.bar")
    assert n() == 1
    logger.enable("foo.bar")
    assert n() == 2
    logger.disable("foo.bar.baz")
    assert n() == 3
    logger.disable("foo.baz")
    assert n() == 3
    logger.disable("foo.baz.bar")
    assert n() == 3
    logger.enable("foo.baz.bar")
    assert n() == 4
    logger.enable("")
    assert n() == 0 
開發者ID:Delgan,項目名稱:loguru,代碼行數:30,代碼來源:test_activation.py

示例14: test_log_before_enable_f_globals_name_absent

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_log_before_enable_f_globals_name_absent(writer, f_globals_name_absent):
    logger.add(writer, format="{message}")
    logger.disable(None)
    logger.debug("nope")
    logger.enable(None)
    logger.debug("yes")
    result = writer.read()
    assert result == "yes\n" 
開發者ID:Delgan,項目名稱:loguru,代碼行數:10,代碼來源:test_activation.py

示例15: test_f_globals_name_absent_with_others

# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import enable [as 別名]
def test_f_globals_name_absent_with_others(writer, f_globals_name_absent):
    logger.add(writer, format="{message}")
    logger.info("1")
    logger.enable(None)
    logger.disable("foobar")
    logger.enable("foo.bar")
    logger.disable(None)
    logger.info("2")
    logger.enable("foobar")
    logger.enable(None)
    logger.info("3")
    assert writer.read() == "1\n3\n" 
開發者ID:Delgan,項目名稱:loguru,代碼行數:14,代碼來源:test_activation.py


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