In loguru, the add
method returns a logger id, which can be used to remove a logger that is no longer useful (with the remove
method). This is mentioned here in the documentation.
This translates as:
from loguru import logger
if __name__ == "__main__":
dummy_logger_id: int = logger.add("dummy.log", format="{time:DD-MM-YYYY HH:mm:ss} {level} {message}")
logger.info("Only dummy")
test_logger_id: int = logger.add("test.log", format="{time:DD-MM-YYYY HH:mm:ss} {level} {message}")
logger.info("Both")
logger.remove(dummy_logger_id)
logger.info("Only test")
This results in two files, dummy.log
and test.log
:
dummy.log
15-07-2022 08:15:12 INFO Only dummy
15-07-2022 08:15:12 INFO Both
test.log
15-07-2022 08:15:12 INFO Both
15-07-2022 08:15:12 INFO Only test