本文整理匯總了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 == ""
示例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)
示例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)
示例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")
示例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"
示例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")
示例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"
示例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"
示例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"
示例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 == ""
示例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"
示例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() == ""
示例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")
示例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"
示例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"