From 1dca56be86aebd3c21020a0672638b0df000bd94 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 8 Sep 2024 00:56:48 +0300 Subject: [PATCH] Python Log Library examples --- code/Python/loguru.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 code/Python/loguru.py diff --git a/code/Python/loguru.py b/code/Python/loguru.py new file mode 100644 index 0000000..62bed47 --- /dev/null +++ b/code/Python/loguru.py @@ -0,0 +1,27 @@ +import sys + +from loguru import logger + + +def logger_export() -> None: + logger.add("file_1.log", rotation="500 MB") # Automatically rotate too big file + logger.add("file_2.log", rotation="12:00") # New file is created each day at noon + logger.add("file_3.log", rotation="1 week") # Once the file is too old, it's rotated + logger.add("file_X.log", retention="10 days") # Cleanup after some time + logger.add("file_Y.log", compression="zip") # Save some loved space + + +def main(): + logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO") + + logger.trace("trace") + logger.debug("debug") + logger.info("info") + logger.success("success") + logger.warning("warning") + logger.error("error") + logger.critical("critical") + + +if __name__ == '__main__': + main()