本文整理汇总了Python中loguru.logger.remove方法的典型用法代码示例。如果您正苦于以下问题:Python logger.remove方法的具体用法?Python logger.remove怎么用?Python logger.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类loguru.logger
的用法示例。
在下文中一共展示了logger.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_logger
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [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)
示例2: configure
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def configure(ctx):
"""
Configure the following application settings:
(1) Default encoding to load files.
(2) HTTP/HTTPS proxy server URI (for url sub-command).
Configurations are written to '~/.sqlitebiter'.
You can remove these settings by deleting '~/.sqlitebiter'.
"""
initialize_logger("{:s} file".format(PROGRAM_NAME), ctx.obj[Context.LOG_LEVEL])
logger.debug("{} configuration file existence: {}".format(PROGRAM_NAME, app_config_mgr.exists))
sys.exit(app_config_mgr.configure())
示例3: setup_logger
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [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")
示例4: set_log_level
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def set_log_level(log_level):
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.remove()
logger.add(sys.stderr, colorize=True, format=log_format, level=log_level)
if log_level == "QUIET":
set_logger(is_enable=False)
else:
set_logger(is_enable=True)
示例5: test_safe_logging
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_safe_logging():
barrier = Barrier(2)
counter = itertools.count()
sink = NonSafeSink(1)
logger.add(sink, format="{message}", catch=False)
def threaded():
barrier.wait()
logger.info("___{}___", next(counter))
threads = [Thread(target=threaded) for _ in range(2)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
logger.remove()
assert sink.written in ("___0___\n___1___\n", "___1___\n___0___\n")
示例6: test_heavily_threaded_logging
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_heavily_threaded_logging(capsys):
logger.remove()
def function():
i = logger.add(NonSafeSink(0.1), format="{message}", catch=False)
logger.debug("AAA")
logger.info("BBB")
logger.success("CCC")
logger.remove(i)
threads = [Thread(target=function) for _ in range(10)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
logger.remove()
out, err = capsys.readouterr()
assert out == ""
assert err == ""
示例7: test_remove_propagation
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_remove_propagation(make_logging_logger, capsys):
logging_logger = make_logging_logger("tests", StreamHandler(sys.stderr))
i = logger.add(PropagateHandler(), format="{message}")
logger.debug("1")
logging_logger.debug("2")
logger.remove(i)
logger.debug("3")
logging_logger.debug("4")
out, err = capsys.readouterr()
assert out == ""
assert err == "1\n2\n4\n"
示例8: test_size_rotation
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_size_rotation(monkeypatch_date, tmpdir, size):
monkeypatch_date(2018, 1, 1, 0, 0, 0, 0)
file = tmpdir.join("test_{time}.log")
i = logger.add(str(file), format="{message}", rotation=size, mode="w")
monkeypatch_date(2018, 1, 1, 0, 0, 1, 0)
logger.debug("abcde")
monkeypatch_date(2018, 1, 1, 0, 0, 2, 0)
logger.debug("fghij")
monkeypatch_date(2018, 1, 1, 0, 0, 3, 0)
logger.debug("klmno")
monkeypatch_date(2018, 1, 1, 0, 0, 4, 0)
logger.remove(i)
assert len(tmpdir.listdir()) == 3
assert tmpdir.join("test_2018-01-01_00-00-00_000000.log").read() == "abcde\n"
assert tmpdir.join("test_2018-01-01_00-00-02_000000.log").read() == "fghij\n"
assert tmpdir.join("test_2018-01-01_00-00-03_000000.log").read() == "klmno\n"
示例9: test_time_rotation
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_time_rotation(monkeypatch_date, darwin_filesystem, tmpdir, when, hours):
now = datetime.datetime(2017, 6, 18, 12, 0, 0) # Sunday
monkeypatch_date(
now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond
)
i = logger.add(str(tmpdir.join("test_{time}.log")), format="{message}", rotation=when, mode="w")
for h, m in zip(hours, ["a", "b", "c", "d", "e"]):
now += datetime.timedelta(hours=h)
monkeypatch_date(
now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond
)
logger.debug(m)
logger.remove(i)
assert [f.read() for f in sorted(tmpdir.listdir())] == ["a\n", "b\nc\n", "d\n", "e\n"]
示例10: test_time_rotation_dst
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_time_rotation_dst(monkeypatch_date, darwin_filesystem, tmpdir):
monkeypatch_date(2018, 10, 27, 5, 0, 0, 0, "CET", 3600)
i = logger.add(str(tmpdir.join("test_{time}.log")), format="{message}", rotation="1 day")
logger.debug("First")
monkeypatch_date(2018, 10, 28, 5, 30, 0, 0, "CEST", 7200)
logger.debug("Second")
monkeypatch_date(2018, 10, 29, 6, 0, 0, 0, "CET", 3600)
logger.debug("Third")
logger.remove(i)
assert len(tmpdir.listdir()) == 3
assert tmpdir.join("test_2018-10-27_05-00-00_000000.log").read() == "First\n"
assert tmpdir.join("test_2018-10-28_05-30-00_000000.log").read() == "Second\n"
assert tmpdir.join("test_2018-10-29_06-00-00_000000.log").read() == "Third\n"
示例11: test_caught_exception_queue_get
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_caught_exception_queue_get(writer, capsys):
logger.add(writer, enqueue=True, catch=True, format="{message}")
logger.info("It's fine")
logger.bind(broken=NotUnpicklable()).info("Bye bye...")
logger.info("It's fine again")
logger.remove()
out, err = capsys.readouterr()
lines = err.strip().splitlines()
assert writer.read() == "It's fine\nIt's fine again\n"
assert out == ""
assert lines[0] == "--- Logging error in Loguru Handler #0 ---"
assert lines[1] == "Record was: None"
assert lines[-2] == "RuntimeError: You shall not de-serialize me!"
assert lines[-1] == "--- End of logging error ---"
示例12: test_manage_formatted_files
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_manage_formatted_files(monkeypatch_date, tmpdir):
monkeypatch_date(2018, 1, 1, 0, 0, 0, 0)
f1 = tmpdir.join("temp/2018/file.log")
f2 = tmpdir.join("temp/file2018.log")
f3 = tmpdir.join("temp/d2018/f2018.2018.log")
a = logger.add(str(tmpdir.join("temp/{time:YYYY}/file.log")), retention=0)
b = logger.add(str(tmpdir.join("temp/file{time:YYYY}.log")), retention=0)
c = logger.add(str(tmpdir.join("temp/d{time:YYYY}/f{time:YYYY}.{time:YYYY}.log")), retention=0)
logger.debug("test")
assert f1.check(exists=1)
assert f2.check(exists=1)
assert f3.check(exists=1)
logger.remove(a)
logger.remove(b)
logger.remove(c)
assert f1.check(exists=0)
assert f2.check(exists=0)
assert f3.check(exists=0)
示例13: test_rename_existing_with_creation_time
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_rename_existing_with_creation_time(monkeypatch, tmpdir):
def creation_time(filepath):
assert os.path.isfile(filepath)
assert os.path.basename(filepath) == "test.log.tar.gz"
return datetime.datetime(2018, 1, 1, 0, 0, 0, 0).timestamp()
i = logger.add(str(tmpdir.join("test.log")), compression="tar.gz")
logger.debug("test")
logger.remove(i)
j = logger.add(str(tmpdir.join("test.log")), compression="tar.gz")
logger.debug("test")
filesink = next(iter(logger._core.handlers.values()))._sink
monkeypatch.setattr(loguru._file_sink, "get_ctime", creation_time)
logger.remove(j)
assert len(tmpdir.listdir()) == 2
assert tmpdir.join("test.log.tar.gz").check(exists=1)
assert tmpdir.join("test.2018-01-01_00-00-00_000000.log.tar.gz").check(exists=1)
示例14: test_renaming_compression_dest_exists
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_renaming_compression_dest_exists(monkeypatch, monkeypatch_date, tmpdir):
date = (2019, 1, 2, 3, 4, 5, 6)
timestamp = datetime.datetime(*date).timestamp()
monkeypatch_date(*date)
monkeypatch.setattr(loguru._file_sink, "get_ctime", lambda _: timestamp)
for i in range(4):
logger.add(str(tmpdir.join("rotate.log")), compression=".tar.gz", format="{message}")
logger.info(str(i))
logger.remove()
assert len(tmpdir.listdir()) == 4
assert tmpdir.join("rotate.log.tar.gz").check(exists=1)
assert tmpdir.join("rotate.2019-01-02_03-04-05_000006.log.tar.gz").check(exists=1)
assert tmpdir.join("rotate.2019-01-02_03-04-05_000006.2.log.tar.gz").check(exists=1)
assert tmpdir.join("rotate.2019-01-02_03-04-05_000006.3.log.tar.gz").check(exists=1)
示例15: test_renaming_compression_dest_exists_with_time
# 需要导入模块: from loguru import logger [as 别名]
# 或者: from loguru.logger import remove [as 别名]
def test_renaming_compression_dest_exists_with_time(monkeypatch, monkeypatch_date, tmpdir):
date = (2019, 1, 2, 3, 4, 5, 6)
timestamp = datetime.datetime(*date).timestamp()
monkeypatch_date(*date)
monkeypatch.setattr(loguru._file_sink, "get_ctime", lambda _: timestamp)
for i in range(4):
logger.add(str(tmpdir.join("rotate.{time}.log")), compression=".tar.gz", format="{message}")
logger.info(str(i))
logger.remove()
assert len(tmpdir.listdir()) == 4
assert tmpdir.join("rotate.2019-01-02_03-04-05_000006.log.tar.gz").check(exists=1)
assert tmpdir.join(
"rotate.2019-01-02_03-04-05_000006.2019-01-02_03-04-05_000006.log.tar.gz"
).check(exists=1)
assert tmpdir.join(
"rotate.2019-01-02_03-04-05_000006.2019-01-02_03-04-05_000006.2.log.tar.gz"
).check(exists=1)
assert tmpdir.join(
"rotate.2019-01-02_03-04-05_000006.2019-01-02_03-04-05_000006.3.log.tar.gz"
).check(exists=1)